From 0faf690a3db47a099ffd5d7eda468425826d0584 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Mon, 4 May 2026 23:33:43 +0200 Subject: [PATCH] Match SourceViewer canvas background to text widget The 1px gap between the vertical ruler and the text widget is rendered by RulerLayout against the parent canvas, which kept its system default background. On dark editor themes this surfaced as a bright vertical strip between the line numbers and the source. Track the StyledText background and apply it to the canvas, so the gap blends into the editor color scheme. Re-syncs on text widget paint events so preference-driven background changes propagate. Fixes https://github.com/eclipse-platform/eclipse.platform.ui/issues/3964 --- .../jface/text/source/SourceViewer.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java index e63b1b5162c..8ef74c588d4 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java @@ -26,6 +26,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; @@ -468,6 +469,25 @@ protected void createControl(Composite parent, int styles) { if (fOverviewRuler != null) { fOverviewRuler.createControl(fComposite, this); } + + if (fComposite != null) { + StyledText textWidget= getTextWidget(); + if (textWidget != null) { + // Match the canvas background to the text widget so the RulerLayout gap blends in. + syncCompositeBackground(textWidget); + textWidget.addPaintListener(e -> syncCompositeBackground(textWidget)); + } + } + } + + private void syncCompositeBackground(StyledText textWidget) { + if (fComposite == null || fComposite.isDisposed() || textWidget.isDisposed()) { + return; + } + Color desired= textWidget.getBackground(); + if (desired != null && !desired.equals(fComposite.getBackground())) { + fComposite.setBackground(desired); + } } /**