From f0ce62ead884a33b65868efa6702102d2481e158 Mon Sep 17 00:00:00 2001 From: JonasKaplan <94881921+JonasKaplan@users.noreply.github.com> Date: Mon, 9 Jun 2025 16:48:49 -0400 Subject: [PATCH] editor: Add trailing whitespace rendering (#32329) Closes #5237 - Adds "trailing" option for "show_whitespaces" in settings.json - Supports importing this setting from vscode The option in question will render only whitespace characters that appear after every non-whitespace character in a given line. Release Notes: - Added trailing whitespace rendering --- crates/editor/src/element.rs | 11 +++++++++++ crates/language/src/language_settings.rs | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e5a0eb616e..52101f35fd 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -7329,6 +7329,17 @@ impl LineWithInvisibles { paint(window, cx); }), + ShowWhitespaceSetting::Trailing => { + let mut previous_start = self.len; + for ([start, end], paint) in invisible_iter.rev() { + if previous_start != end { + break; + } + previous_start = start; + paint(window, cx); + } + } + // For a whitespace to be on a boundary, any of the following conditions need to be met: // - It is a tab // - It is adjacent to an edge (start or end) diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index daaf4ef35d..6793329b61 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -765,6 +765,8 @@ pub enum ShowWhitespaceSetting { /// - It is adjacent to an edge (start or end) /// - It is adjacent to a whitespace (left or right) Boundary, + /// Draw whitespaces only after non-whitespace characters. + Trailing, } /// Controls which formatter should be used when formatting code. @@ -1452,7 +1454,8 @@ impl settings::Settings for AllLanguageSettings { vscode.bool_setting("editor.inlineSuggest.enabled", &mut d.show_edit_predictions); vscode.enum_setting("editor.renderWhitespace", &mut d.show_whitespaces, |s| { Some(match s { - "boundary" | "trailing" => ShowWhitespaceSetting::Boundary, + "boundary" => ShowWhitespaceSetting::Boundary, + "trailing" => ShowWhitespaceSetting::Trailing, "selection" => ShowWhitespaceSetting::Selection, "all" => ShowWhitespaceSetting::All, _ => ShowWhitespaceSetting::None,