Skip to content

Commit

Permalink
Fix: Correctly align line numbers in sticky lines control
Browse files Browse the repository at this point in the history
The line number in the sticky lines control and in the editor control are correctly aligned with this change.

Fixes eclipse-platform#1965
  • Loading branch information
Christopher-Hermann authored and BeckerWdf committed Jul 10, 2024
1 parent 43df788 commit 7ab381c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ private void createControls() {
GridDataFactory.fillDefaults().grab(true, false).indent(0, BOTTOM_SEPARATOR_SPACING).span(2, 1).applyTo(bottomSeparator);
bottomSeparator.setEnabled(false);

layoutLineNumbers();

stickyLinesCanvas.pack();
stickyLinesCanvas.moveAbove(null);
}
Expand All @@ -210,7 +212,7 @@ private void updateStickyScrollingControls() {
}

private String fillLineNumberWithLeadingSpaces(int lineNumber) {
int lineCount= sourceViewer.getTextWidget().getLineCount();
int lineCount= sourceViewer.getDocument().getNumberOfLines();
int lineNumberLength= String.valueOf(lineCount).length();
String formatString= "%" + lineNumberLength + "d"; //$NON-NLS-1$ //$NON-NLS-2$
return String.format(formatString, lineNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void setup() {
shell.setLayout(new FillLayout());
ruler = new CompositeRuler();
sourceViewer = new SourceViewer(shell, ruler, SWT.V_SCROLL | SWT.H_SCROLL);
sourceViewer.setDocument(new Document());

lineNumberColor = new Color(0, 0, 0);
hoverColor = new Color(1, 1, 1);
Expand Down Expand Up @@ -126,7 +127,7 @@ public void testLimitStickyLinesCount() {

@Test
public void testCopyStyleRanges() {
sourceViewer.getTextWidget().setText("line 1");
sourceViewer.setInput(new Document("line 1"));
sourceViewer.getTextWidget().setStyleRange(new StyleRange(0, 6, lineNumberColor, backgroundColor));

List<StickyLine> stickyLines = List.of(new StickyLine("line 1", 0));
Expand Down Expand Up @@ -198,9 +199,8 @@ public void testNavigateToStickyLine() {
String text = """
line 1
line 2""";
sourceViewer.getTextWidget().setText(text);
sourceViewer.setInput(new Document(text));
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);
sourceViewer.setDocument(new Document(text));

List<StickyLine> stickyLines = List.of(new StickyLine("line 2", 1));
stickyScrollingControl.setStickyLines(stickyLines);
Expand All @@ -219,7 +219,7 @@ public void testVerticalScrollingIsDispatched() {
String text = """
line 1
line 2""";
sourceViewer.getTextWidget().setText(text);
sourceViewer.setInput(new Document(text));
sourceViewer.getTextWidget().getVerticalBar().setIncrement(10);
assertEquals(0, sourceViewer.getTextWidget().getTopPixel());

Expand All @@ -236,7 +236,7 @@ public void testHorizontalScrollingIsDispatched() {
String text = """
line 1
line 2""";
sourceViewer.getTextWidget().setText(text);
sourceViewer.setInput(new Document(text));
sourceViewer.getTextWidget().getHorizontalBar().setIncrement(10);
assertEquals(0, sourceViewer.getTextWidget().getHorizontalPixel());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceStore;

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

Expand All @@ -62,6 +63,7 @@ public void setup() {
shell = new Shell(Display.getDefault());
ruler = new CompositeRuler();
sourceViewer = new SourceViewer(shell, ruler, SWT.None);
sourceViewer.setDocument(new Document());

lineNumberColor = new Color(0, 0, 0);
hoverColor = new Color(1, 1, 1);
Expand Down

0 comments on commit 7ab381c

Please sign in to comment.