Skip to content

Commit 74c6846

Browse files
Christopher-Hermannpraveen-skp
authored andcommitted
Fix "Show line numbers" settings is not correctly handled
When changing the "Show line numbers" setting for the editor, the sticky scrolling control should also react on the setting and hide the line numbers. Fixes eclipse-platform#2269
1 parent 715befb commit 74c6846

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public void applySettings(StickyScrollingControlSettings newSettings) {
150150
bottomSeparator.setBackground(settings.stickyLinesSeparatorColor());
151151

152152
updateStickyScrollingControls();
153+
styleStickyLines();
154+
layoutStickyLines();
153155
}
154156

155157
public void dispose() {
@@ -298,15 +300,12 @@ private void layoutLineNumbers() {
298300
return;
299301
}
300302

303+
LineNumberColumn lineNumberColumn= getLineNumberColumn(verticalRuler);
301304
if (!settings.showLineNumbers()) {
302305
stickyLineNumber.setRightMargin(verticalRuler.getWidth());
303306
((GridData) stickyLineNumber.getLayoutData()).widthHint= 0;
304307
stickyLineNumber.setLeftMargin(0);
305-
return;
306-
}
307-
308-
LineNumberColumn lineNumberColumn= getLineNumberColumn(verticalRuler);
309-
if (lineNumberColumn == null) {
308+
} else if (lineNumberColumn == null) {
310309
((GridData) stickyLineNumber.getLayoutData()).widthHint= verticalRuler.getWidth();
311310
GC gc= new GC(stickyLinesCanvas);
312311
gc.setFont(sourceViewer.getTextWidget().getFont());

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import static org.hamcrest.Matchers.greaterThan;
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertFalse;
20+
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.when;
2022

2123
import java.util.List;
2224

@@ -41,7 +43,7 @@
4143
import org.eclipse.swt.widgets.Shell;
4244

4345
import org.eclipse.jface.text.Document;
44-
import org.eclipse.jface.text.source.CompositeRuler;
46+
import org.eclipse.jface.text.source.IVerticalRuler;
4547
import org.eclipse.jface.text.source.SourceViewer;
4648

4749
public class StickyScrollingControlTest {
@@ -53,14 +55,14 @@ public class StickyScrollingControlTest {
5355
private Color backgroundColor;
5456
private Color separatorColor;
5557
private StickyScrollingControl stickyScrollingControl;
56-
private CompositeRuler ruler;
58+
private IVerticalRuler ruler;
5759

5860
@Before
5961
public void setup() {
6062
shell = new Shell(Display.getDefault());
6163
shell.setSize(200, 200);
6264
shell.setLayout(new FillLayout());
63-
ruler = new CompositeRuler();
65+
ruler = mock(IVerticalRuler.class);
6466
sourceViewer = new SourceViewer(shell, ruler, SWT.V_SCROLL | SWT.H_SCROLL);
6567
sourceViewer.setDocument(new Document());
6668
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);
@@ -153,6 +155,23 @@ public void testWithoutVerticalRuler() {
153155
assertFalse(stickyLineNumber.isVisible());
154156
}
155157

158+
@Test
159+
public void testWithoutLineNumber() {
160+
when(ruler.getWidth()).thenReturn(20);
161+
List<StickyLine> stickyLines = List.of(new StickyLine("line 10", 9), new StickyLine("line 20", 19));
162+
stickyScrollingControl.setStickyLines(stickyLines);
163+
164+
StyledText stickyLineNumber = getStickyLineNumber();
165+
assertThat(stickyLineNumber.getLeftMargin(), greaterThan(0));
166+
167+
StickyScrollingControlSettings settings = new StickyScrollingControlSettings(5, lineNumberColor, hoverColor,
168+
backgroundColor, separatorColor, false);
169+
stickyScrollingControl.applySettings(settings);
170+
171+
stickyLineNumber = getStickyLineNumber();
172+
assertEquals(0, stickyLineNumber.getLeftMargin());
173+
}
174+
156175
@Test
157176
public void testStyling() {
158177
Font font = new Font(shell.getDisplay(), new FontData("Arial", 12, SWT.BOLD));

0 commit comments

Comments
 (0)