diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java index b62bae32287..9b82b5ab02e 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java @@ -55,7 +55,7 @@ public StyleRange[] getStyleRanges() { StyledText textWidget= sourceViewer.getTextWidget(); int widgetLineNumber = getWidgetLineNumber(); - if (widgetLineNumber > textWidget.getLineCount()) { + if (widgetLineNumber >= textWidget.getLineCount()) { return null; } diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java index b79afafa243..3da1b67caf4 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java @@ -441,7 +441,7 @@ public void controlMoved(ControlEvent e) { private boolean areStickyLinesOutDated(StyledText textWidget) { if (stickyLines.size() > 0) { int lastStickyLineNumber = stickyLines.get(stickyLines.size() - 1).getLineNumber(); - return lastStickyLineNumber > textWidget.getLineCount(); + return lastStickyLineNumber >= textWidget.getLineCount(); } return false; } diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java index 5c34d24f0db..aeace6c47c2 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java @@ -100,9 +100,10 @@ public void testGetStyleRangesIgnoresOutOfBoundLines() { textWidget.setText("line1\nline2\nline3"); StickyLine stickyLineOutOfBound = new StickyLine(10, sourceViewer); - StyleRange[] styleRanges = stickyLineOutOfBound.getStyleRanges(); + assertNull(stickyLineOutOfBound.getStyleRanges()); - assertNull(styleRanges); + stickyLineOutOfBound = new StickyLine(3, sourceViewer); + assertNull(stickyLineOutOfBound.getStyleRanges()); } @Test diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java index 04fdfd18012..c44151f879f 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java @@ -256,7 +256,7 @@ public void testLayoutStickyLinesCanvasOnResize() { public void testDontLayoutOutDatedStickyLinesOnResize() { sourceViewer.getTextWidget().setBounds(0, 0, 200, 200); - List stickyLines = List.of(new StickyLineStub("line 10", 10)); + List stickyLines = List.of(new StickyLineStub("line 1", 1)); stickyScrollingControl.setStickyLines(stickyLines); Canvas stickyControlCanvas = getStickyControlCanvas(shell); @@ -329,6 +329,7 @@ public void testHorizontalScrollingIsDispatched() { @Test public void testLimitStickyLinesToTextWidgetHeight() { sourceViewer.getTextWidget().setBounds(0, 0, 200, 200); + sourceViewer.getTextWidget().setText("line1\nline2"); List stickyLines = List.of(new StickyLineStub("line 2", 1)); stickyScrollingControl.setStickyLines(stickyLines);