Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sticky Scrolling] Fix "Show line numbers" settings is not correctly handled #2328

Merged
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 @@ -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
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
Loading