From ffa83fd605562d694b66a66a6eee297211afa8ed Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 1 Oct 2025 09:00:20 +0200 Subject: [PATCH] add editor config --- assets/settings/default.json | 2 + crates/editor/src/editor_settings.rs | 4 ++ crates/editor/src/element.rs | 49 ++++++++++++------- .../settings/src/settings_content/editor.rs | 4 ++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 5107a7f64f3a57bfb612476797fb3c6659f79b4e..c230adad8f245b3570a7604d1cbd2affec1bdd7e 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -593,6 +593,8 @@ // happens when a user holds the alt or option key while scrolling. "fast_scroll_sensitivity": 4.0, "relative_line_numbers": false, + // Whether to show relative line numbers for wrapped lines as well as buffer lines. + "relative_line_numbers_for_wrapped_lines": false, // If 'search_wrap' is disabled, search result do not wrap around the end of the file. "search_wrap": true, // Search options to enable by default when opening new project and buffer searches. diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index dc67ab3ed6c8cfdbe88809e32d615789c01eef60..9dafaad0472f4b39c52d08a3dc818fc223e69f17 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -34,6 +34,7 @@ pub struct EditorSettings { pub scroll_sensitivity: f32, pub fast_scroll_sensitivity: f32, pub relative_line_numbers: bool, + pub relative_line_numbers_for_wrapped_lines: bool, pub seed_search_query_from_cursor: SeedQuerySetting, pub use_smartcase_search: bool, pub multi_cursor_modifier: MultiCursorModifier, @@ -234,6 +235,9 @@ impl Settings for EditorSettings { scroll_sensitivity: editor.scroll_sensitivity.unwrap(), fast_scroll_sensitivity: editor.fast_scroll_sensitivity.unwrap(), relative_line_numbers: editor.relative_line_numbers.unwrap(), + relative_line_numbers_for_wrapped_lines: editor + .relative_line_numbers_for_wrapped_lines + .unwrap(), seed_search_query_from_cursor: editor.seed_search_query_from_cursor.unwrap(), use_smartcase_search: editor.use_smartcase_search.unwrap(), multi_cursor_modifier: editor.multi_cursor_modifier.unwrap(), diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index d8f66e9c87dd2514afe50cccf6c12cefd00cd7f8..ec2a6bb30d050f26743219cd2955d381e5cd1abb 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -3224,33 +3224,44 @@ impl EditorElement { return Arc::default(); } - let (newest_selection_head, is_relative) = self.editor.update(cx, |editor, cx| { - let newest_selection_head = newest_selection_head.unwrap_or_else(|| { - let newest = editor - .selections - .newest::(&editor.display_snapshot(cx)); - SelectionLayout::new( - newest, - editor.selections.line_mode(), - editor.cursor_shape, - &snapshot.display_snapshot, - true, - true, - None, + let (newest_selection_head, is_relative, use_relative_for_wrapped_lines) = + self.editor.update(cx, |editor, cx| { + let newest_selection_head = newest_selection_head.unwrap_or_else(|| { + let newest = editor + .selections + .newest::(&editor.display_snapshot(cx)); + SelectionLayout::new( + newest, + editor.selections.line_mode(), + editor.cursor_shape, + &snapshot.display_snapshot, + true, + true, + None, + ) + .head + }); + let is_relative = editor.should_use_relative_line_numbers(cx); + let use_relative_for_wrapped_lines = is_relative + && EditorSettings::get_global(cx).relative_line_numbers_for_wrapped_lines; + ( + newest_selection_head, + is_relative, + use_relative_for_wrapped_lines, ) - .head }); - let is_relative = editor.should_use_relative_line_numbers(cx); - (newest_selection_head, is_relative) - }); let relative_to = if is_relative { Some(newest_selection_head.row()) } else { None }; - let relative_rows = - self.calculate_relative_line_numbers(snapshot, &rows, relative_to, true); + let relative_rows = self.calculate_relative_line_numbers( + snapshot, + &rows, + relative_to, + use_relative_for_wrapped_lines, + ); let mut line_number = String::new(); let segments = buffer_rows.iter().enumerate().flat_map(|(ix, row_info)| { let display_row = DisplayRow(rows.start.0 + ix as u32); diff --git a/crates/settings/src/settings_content/editor.rs b/crates/settings/src/settings_content/editor.rs index 4b00cd24500999eb917bf2117fd17b557d2509ae..6b2a61c4d42d40a8ff2eff744ff67a3907e44591 100644 --- a/crates/settings/src/settings_content/editor.rs +++ b/crates/settings/src/settings_content/editor.rs @@ -94,6 +94,10 @@ pub struct EditorSettingsContent { /// /// Default: false pub relative_line_numbers: Option, + /// Whether to show relative line numbers for wrapped lines (visual lines) rather than just buffer lines. + /// + /// Default: false + pub relative_line_numbers_for_wrapped_lines: Option, /// When to populate a new search's query based on the text under the cursor. /// /// Default: always