Skip to content

Commit

Permalink
Fix "Show line numbers" settings is not correctly handled
Browse files Browse the repository at this point in the history
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 #2269
  • Loading branch information
Christopher-Hermann committed Sep 26, 2024
1 parent 0fa0c4b commit 14eff16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public void applySettings(StickyScrollingControlSettings newSettings) {
bottomSeparator.setBackground(settings.stickyLinesSeparatorColor());

updateStickyScrollingControls();
styleStickyLines();
layoutStickyLines();
}

public void dispose() {
Expand Down Expand Up @@ -298,15 +300,12 @@ private void layoutLineNumbers() {
return;
}

LineNumberColumn lineNumberColumn= getLineNumberColumn(verticalRuler);
if (!settings.showLineNumbers()) {
stickyLineNumber.setRightMargin(verticalRuler.getWidth());
((GridData) stickyLineNumber.getLayoutData()).widthHint= 0;
stickyLineNumber.setLeftMargin(0);
return;
}

LineNumberColumn lineNumberColumn= getLineNumberColumn(verticalRuler);
if (lineNumberColumn == null) {
} else if (lineNumberColumn == null) {
((GridData) stickyLineNumber.getLayoutData()).widthHint= verticalRuler.getWidth();
GC gc= new GC(stickyLinesCanvas);
gc.setFont(sourceViewer.getTextWidget().getFont());
Expand Down
4 changes: 3 additions & 1 deletion tests/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Require-Bundle:
org.eclipse.jface.text;bundle-version="3.19.0",
org.eclipse.ui;bundle-version="3.119.100",
org.eclipse.ui.tests.harness;bundle-version="1.8.0",
org.mockito.mockito-core;bundle-version="5.12.0"
org.mockito.mockito-core;bundle-version="5.13.0",
net.bytebuddy.byte-buddy;bundle-version="1.15.1",
net.bytebuddy.byte-buddy-agent;bundle-version="1.15.1"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;

Expand All @@ -41,7 +43,7 @@
import org.eclipse.swt.widgets.Shell;

import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.source.CompositeRuler;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewer;

public class StickyScrollingControlTest {
Expand All @@ -53,14 +55,14 @@ public class StickyScrollingControlTest {
private Color backgroundColor;
private Color separatorColor;
private StickyScrollingControl stickyScrollingControl;
private CompositeRuler ruler;
private IVerticalRuler ruler;

@Before
public void setup() {
shell = new Shell(Display.getDefault());
shell.setSize(200, 200);
shell.setLayout(new FillLayout());
ruler = new CompositeRuler();
ruler = mock(IVerticalRuler.class);
sourceViewer = new SourceViewer(shell, ruler, SWT.V_SCROLL | SWT.H_SCROLL);
sourceViewer.setDocument(new Document());
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);
Expand Down Expand Up @@ -153,6 +155,23 @@ public void testWithoutVerticalRuler() {
assertFalse(stickyLineNumber.isVisible());
}

@Test
public void testWithoutLineNumber() {
when(ruler.getWidth()).thenReturn(20);
List<StickyLine> stickyLines = List.of(new StickyLine("line 10", 9), new StickyLine("line 20", 19));
stickyScrollingControl.setStickyLines(stickyLines);

StyledText stickyLineNumber = getStickyLineNumber();
assertThat(stickyLineNumber.getLeftMargin(), greaterThan(0));

StickyScrollingControlSettings settings = new StickyScrollingControlSettings(5, lineNumberColor, hoverColor,
backgroundColor, separatorColor, false);
stickyScrollingControl.applySettings(settings);

stickyLineNumber = getStickyLineNumber();
assertEquals(0, stickyLineNumber.getLeftMargin());
}

@Test
public void testStyling() {
Font font = new Font(shell.getDisplay(), new FontData("Arial", 12, SWT.BOLD));
Expand Down

0 comments on commit 14eff16

Please sign in to comment.