Skip to content

Commit e4489cf

Browse files
committed
Add support for line background to sticky scrolling
Some text editors uses line background to style the editor's text. This change adds support to specify the line background of sticky lines too, so that they can be styled like in the editor.
1 parent 0b9521c commit e4489cf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.custom.CaretEvent;
2323
import org.eclipse.swt.custom.CaretListener;
24+
import org.eclipse.swt.custom.LineBackgroundEvent;
2425
import org.eclipse.swt.custom.StyleRange;
2526
import org.eclipse.swt.custom.StyledText;
2627
import org.eclipse.swt.events.ControlEvent;
@@ -185,6 +186,7 @@ private void createControls() {
185186
GridDataFactory.fillDefaults().grab(true, true).applyTo(stickyLineText);
186187
stickyLineText.setEnabled(false);
187188
stickyLineText.setBackground(settings.stickyLineBackgroundColor());
189+
stickyLineText.addLineBackgroundListener(this::styleStickyLineBackground);
188190

189191
bottomSeparator= new Composite(stickyLinesCanvas, SWT.NONE);
190192
GridDataFactory.fillDefaults().hint(0, 3).grab(true, false).span(2, 1).applyTo(bottomSeparator);
@@ -260,6 +262,12 @@ private void styleStickyLines() {
260262
stickyLineText.setLeftMargin(textWidget.getLeftMargin());
261263
}
262264

265+
private void styleStickyLineBackground(LineBackgroundEvent event) {
266+
int lineIndex = stickyLineText.getLineAtOffset(event.lineOffset);
267+
IStickyLine line = stickyLines.get(lineIndex);
268+
event.lineBackground = line.getBackgroundColor();
269+
}
270+
263271
private void layoutStickyLines() {
264272
if (getNumberStickyLines() == 0) {
265273
stickyLinesCanvas.setVisible(false);

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/stickyscroll/IStickyLine.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.ui.texteditor.stickyscroll;
1515

1616
import org.eclipse.swt.custom.StyleRange;
17+
import org.eclipse.swt.graphics.Color;
1718

1819
/**
1920
* Representation of a sticky line.
@@ -43,4 +44,23 @@ public interface IStickyLine {
4344
*/
4445
StyleRange[] getStyleRanges();
4546

47+
/**
48+
* Returns the background color of the sticky line.
49+
* <p>
50+
* The background color is drawn for the full-width of the line. The text
51+
* background color if defined in a StyleRange ({@link #getStyleRanges()})
52+
* overlays the line background color.
53+
* </p>
54+
* <p>
55+
* {@code null} (the default), if the line has no special background color.
56+
* </p>
57+
*
58+
* @return the background color of the sticky line or {@code null} for no
59+
* special color
60+
* @since 3.22
61+
*/
62+
default Color getBackgroundColor() {
63+
return null;
64+
}
65+
4666
}

0 commit comments

Comments
 (0)