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 @@ -53,6 +53,12 @@ public String getText() {
@Override
public StyleRange[] getStyleRanges() {
StyledText textWidget= sourceViewer.getTextWidget();
int widgetLineNumber = getWidgetLineNumber();

if (widgetLineNumber > textWidget.getLineCount()) {
return null;
}

int offsetAtLine= textWidget.getOffsetAtLine(getWidgetLineNumber());
StyleRange[] styleRanges= textWidget.getStyleRanges(offsetAtLine, getText().length());
for (StyleRange styleRange : styleRanges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.ui.internal.texteditor.stickyscroll;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -94,6 +95,16 @@ public void testGetStyleRanges() {
assertEquals(2, styleRanges[1].length);
}

@Test
public void testGetStyleRangesIgnoresOutOfBoundLines() {
textWidget.setText("line1\nline2\nline3");

StickyLine stickyLineOutOfBound = new StickyLine(10, sourceViewer);
StyleRange[] styleRanges = stickyLineOutOfBound.getStyleRanges();

assertNull(styleRanges);
}

@Test
public void WithSourceViewerLineMapping() {
sourceViewer = new SourceViewerWithLineMapping(shell, null, SWT.None);
Expand Down
Loading