add editor config

Thomas Heartman created

Change summary

assets/settings/default.json                   |  2 
crates/editor/src/editor_settings.rs           |  4 +
crates/editor/src/element.rs                   | 49 ++++++++++++-------
crates/settings/src/settings_content/editor.rs |  4 +
4 files changed, 40 insertions(+), 19 deletions(-)

Detailed changes

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.

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(),

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::<Point>(&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::<Point>(&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);

crates/settings/src/settings_content/editor.rs 🔗

@@ -94,6 +94,10 @@ pub struct EditorSettingsContent {
     ///
     /// Default: false
     pub relative_line_numbers: Option<bool>,
+    /// 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<bool>,
     /// When to populate a new search's query based on the text under the cursor.
     ///
     /// Default: always