From 12f1ef11310ed0b312d9f60f1cec9d1124848c31 Mon Sep 17 00:00:00 2001 From: Stephan Wahlbrink Date: Tue, 31 Mar 2026 10:12:04 +0200 Subject: [PATCH] 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. --- .../.settings/.api_filters | 8 ++++++++ .../stickyscroll/StickyScrollingControl.java | 8 ++++++++ .../texteditor/stickyscroll/IStickyLine.java | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/bundles/org.eclipse.ui.editors/.settings/.api_filters b/bundles/org.eclipse.ui.editors/.settings/.api_filters index c062b4ac10e0..39392e409f01 100644 --- a/bundles/org.eclipse.ui.editors/.settings/.api_filters +++ b/bundles/org.eclipse.ui.editors/.settings/.api_filters @@ -17,4 +17,12 @@ + + + + + + + + diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java index 12bb922768ef..cd0c9518e2c8 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControl.java @@ -21,6 +21,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CaretEvent; import org.eclipse.swt.custom.CaretListener; +import org.eclipse.swt.custom.LineBackgroundEvent; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ControlEvent; @@ -185,6 +186,7 @@ private void createControls() { GridDataFactory.fillDefaults().grab(true, true).applyTo(stickyLineText); stickyLineText.setEnabled(false); stickyLineText.setBackground(settings.stickyLineBackgroundColor()); + stickyLineText.addLineBackgroundListener(this::styleStickyLineBackground); bottomSeparator= new Composite(stickyLinesCanvas, SWT.NONE); GridDataFactory.fillDefaults().hint(0, 3).grab(true, false).span(2, 1).applyTo(bottomSeparator); @@ -260,6 +262,12 @@ private void styleStickyLines() { stickyLineText.setLeftMargin(textWidget.getLeftMargin()); } + private void styleStickyLineBackground(LineBackgroundEvent event) { + int lineIndex = stickyLineText.getLineAtOffset(event.lineOffset); + IStickyLine line = stickyLines.get(lineIndex); + event.lineBackground = line.getBackgroundColor(); + } + private void layoutStickyLines() { if (getNumberStickyLines() == 0) { stickyLinesCanvas.setVisible(false); diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/stickyscroll/IStickyLine.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/stickyscroll/IStickyLine.java index bc8cb26380bb..43bb790df13b 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/stickyscroll/IStickyLine.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/stickyscroll/IStickyLine.java @@ -14,6 +14,7 @@ package org.eclipse.ui.texteditor.stickyscroll; import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.graphics.Color; /** * Representation of a sticky line. @@ -43,4 +44,23 @@ public interface IStickyLine { */ StyleRange[] getStyleRanges(); + /** + * Returns the background color of the sticky line. + *

+ * The background color is drawn for the full-width of the line. The text + * background color if defined in a StyleRange ({@link #getStyleRanges()}) + * overlays the line background color. + *

+ *

+ * {@code null} (the default), if the line has no special background color. + *

+ * + * @return the background color of the sticky line or {@code null} for no + * special color + * @since 3.22 + */ + default Color getBackgroundColor() { + return null; + } + }