From 501b539286db74f011126b12ce5d325ff9914d2e Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Thu, 3 Apr 2025 05:09:42 +0530 Subject: [PATCH] gpui: Fix background for WrappedLine (#27980) https://github.com/zed-industries/zed/pull/26454 In this PR, we separated painting for text line into two parts: `paint` and `paint_background`. This allows selections to appear in front of the text background but behind the text itself in the editor. The `paint_background` method was implemented for `ShapedLine` but not for `WrappedLine`. This PR adds that, fixing the background rendering for inline code blocks in Markdown, as they use `WrappedLine`. Before: image After: image Release Notes: - Fixed missing background for inline code blocks in the editor hover tooltip. --- crates/gpui/src/elements/text.rs | 9 +++++++++ crates/gpui/src/text_system/line.rs | 30 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index cd6cf033db..2407606a66 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -417,6 +417,15 @@ impl TextLayout { let mut line_origin = bounds.origin; let text_style = window.text_style(); for line in &element_state.lines { + line.paint_background( + line_origin, + line_height, + text_style.text_align, + Some(bounds), + window, + cx, + ) + .log_err(); line.paint( line_origin, line_height, diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs index 1ebec668c7..ee351c342a 100644 --- a/crates/gpui/src/text_system/line.rs +++ b/crates/gpui/src/text_system/line.rs @@ -153,6 +153,36 @@ impl WrappedLine { Ok(()) } + + /// Paint the background of line of text to the window. + pub fn paint_background( + &self, + origin: Point, + line_height: Pixels, + align: TextAlign, + bounds: Option>, + window: &mut Window, + cx: &mut App, + ) -> Result<()> { + let align_width = match bounds { + Some(bounds) => Some(bounds.size.width), + None => self.layout.wrap_width, + }; + + paint_line_background( + origin, + &self.layout.unwrapped_layout, + line_height, + align, + align_width, + &self.decoration_runs, + &self.wrap_boundaries, + window, + cx, + )?; + + Ok(()) + } } fn paint_line(