Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ private void addSourceViewerListeners() {
controlListener= new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
if (areStickyLinesOutDated(textWidget)) {
return;
}
limitVisibleStickyLinesToTextWidgetHeight(textWidget);
layoutStickyLines();
if (stickyScrollingHandler != null) {
Expand All @@ -422,6 +425,24 @@ public void controlMoved(ControlEvent e) {
textWidget.addControlListener(controlListener);
}

/**
* Checks if the sticky lines are out dated. Specifically, it verifies that the
* line number of the last sticky line does not exceed the total line count of
* the source viewer.
*
* This situation can occur, for example, when an editor is opened via the
* search view and "reuse editor" is enabled. In such cases, the text in the
* source viewer is replaced, but the out dated sticky lines associated with the
* previous source code remain in the first call.
*/
private boolean areStickyLinesOutDated(StyledText textWidget) {
if (stickyLines.size() > 0) {
int lastStickyLineNumber = stickyLines.get(stickyLines.size() - 1).getLineNumber();
return lastStickyLineNumber > textWidget.getLineCount();
}
return true;
}

private void limitVisibleStickyLinesToTextWidgetHeight(StyledText textWidget) {
int lineHeight= textWidget.getLineHeight() + textWidget.getLineSpacing();
int textWidgetHeight= textWidget.getBounds().height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ public void testLayoutStickyLinesCanvasOnResize() {
assertEquals(boundsAfterResize.height, boundsBeforeResize.height);
}

@Test
public void testDontLayoutOutDatedStickyLinesOnResize() {
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);

List<IStickyLine> stickyLines = List.of(new StickyLineStub("line 10", 10));
stickyScrollingControl.setStickyLines(stickyLines);

Canvas stickyControlCanvas = getStickyControlCanvas(shell);
Rectangle boundsBeforeResize = stickyControlCanvas.getBounds();

sourceViewer.getTextWidget().setBounds(0, 0, 150, 200);

stickyControlCanvas = getStickyControlCanvas(shell);
Rectangle boundsAfterResize = stickyControlCanvas.getBounds();

// No IllegalArgumentException: Index out of bounds
assertEquals(boundsAfterResize, boundsBeforeResize);
}

@Test
public void testNavigateToStickyLine() {
String text = """
Expand Down
Loading