File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll
tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,12 @@ public String getText() {
53
53
@ Override
54
54
public StyleRange [] getStyleRanges () {
55
55
StyledText textWidget = sourceViewer .getTextWidget ();
56
+ int widgetLineNumber = getWidgetLineNumber ();
57
+
58
+ if (widgetLineNumber > textWidget .getLineCount ()) {
59
+ return null ;
60
+ }
61
+
56
62
int offsetAtLine = textWidget .getOffsetAtLine (getWidgetLineNumber ());
57
63
StyleRange [] styleRanges = textWidget .getStyleRanges (offsetAtLine , getText ().length ());
58
64
for (StyleRange styleRange : styleRanges ) {
Original file line number Diff line number Diff line change 14
14
package org .eclipse .ui .internal .texteditor .stickyscroll ;
15
15
16
16
import static org .junit .Assert .assertEquals ;
17
+ import static org .junit .Assert .assertNull ;
17
18
18
19
import org .junit .After ;
19
20
import org .junit .Before ;
@@ -94,6 +95,16 @@ public void testGetStyleRanges() {
94
95
assertEquals (2 , styleRanges [1 ].length );
95
96
}
96
97
98
+ @ Test
99
+ public void testGetStyleRangesIgnoresOutOfBoundLines () {
100
+ textWidget .setText ("line1\n line2\n line3" );
101
+
102
+ StickyLine stickyLineOutOfBound = new StickyLine (10 , sourceViewer );
103
+ StyleRange [] styleRanges = stickyLineOutOfBound .getStyleRanges ();
104
+
105
+ assertNull (styleRanges );
106
+ }
107
+
97
108
@ Test
98
109
public void WithSourceViewerLineMapping () {
99
110
sourceViewer = new SourceViewerWithLineMapping (shell , null , SWT .None );
You can’t perform that action at this time.
0 commit comments