From d7ffc37b149e219eedde6398a2e9369fabc61e85 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 22 Oct 2025 00:05:40 +0800 Subject: [PATCH] editor: Improve text color in document color highlight (#39372) Release Notes: - Improved text color in LSP document color highlight. ---- Because highlight ranges are implemented using a paint background, there's no way to control the text color. I've been thinking about this problem for a long time, want to solve it. ~~Today, I come up with a new idea. Re-rendering the document color text at the top should solve this problem.~~ #### Update 10/6: > The previous version is not good, when we have soft wrap text, that version will not work correct. Now use exists `bg_segments_per_row` feature to fix text color. ## Before image ## After image --- crates/editor/src/element.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index c726de49475ac62eb6c04c05f8163a17218e57cf..944715a0dfa3747bcece23a643a144f891687b53 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -8931,10 +8931,20 @@ impl Element for EditorElement { cx, ); + let merged_highlighted_ranges = + if let Some((_, colors)) = document_colors.as_ref() { + &highlighted_ranges + .clone() + .into_iter() + .chain(colors.clone()) + .collect() + } else { + &highlighted_ranges + }; let bg_segments_per_row = Self::bg_segments_per_row( start_row..end_row, &selections, - &highlighted_ranges, + &merged_highlighted_ranges, self.style.background, );