Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Skip `stop_at_indent` for single-line editors (#50681)
Viraj Bhartiya4842e095d968
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 18a02e9773b..bec38150606 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -14703,6 +14703,7 @@ impl Editor {window: &mut Window,cx: &mut Context<Self>,) {+ let stop_at_indent = action.stop_at_indent && !self.mode.is_single_line();self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx);self.change_selections(Default::default(), window, cx, |s| {s.move_cursors_with(&mut |map, head, _| {@@ -14711,7 +14712,7 @@ impl Editor {map,head,action.stop_at_soft_wraps,- action.stop_at_indent,+ stop_at_indent,),SelectionGoal::None,)@@ -14725,6 +14726,7 @@ impl Editor {window: &mut Window,cx: &mut Context<Self>,) {+ let stop_at_indent = action.stop_at_indent && !self.mode.is_single_line();self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx);self.change_selections(Default::default(), window, cx, |s| {s.move_heads_with(&mut |map, head, _| {@@ -14733,7 +14735,7 @@ impl Editor {map,head,action.stop_at_soft_wraps,- action.stop_at_indent,+ stop_at_indent,),SelectionGoal::None,)diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex fe71cb76f0f..0da80a2a73f 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -1868,6 +1868,56 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {});}+#[gpui::test]+fn test_beginning_of_line_single_line_editor(cx: &mut TestAppContext) {+ init_test(cx, |_| {});++ let editor = cx.add_window(|window, cx| Editor::single_line(window, cx));++ _ = editor.update(cx, |editor, window, cx| {+ editor.set_text(" indented text", window, cx);+ editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {+ s.select_display_ranges([+ DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 10)+ ]);+ });++ editor.move_to_beginning_of_line(+ &MoveToBeginningOfLine {+ stop_at_soft_wraps: true,+ stop_at_indent: true,+ },+ window,+ cx,+ );+ assert_eq!(+ display_ranges(editor, cx),+ &[DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)]+ );+ });++ _ = editor.update(cx, |editor, window, cx| {+ editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {+ s.select_display_ranges([+ DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 10)+ ]);+ });++ editor.select_to_beginning_of_line(+ &SelectToBeginningOfLine {+ stop_at_soft_wraps: true,+ stop_at_indent: true,+ },+ window,+ cx,+ );+ assert_eq!(+ display_ranges(editor, cx),+ &[DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 0)]+ );+ });+}+#[gpui::test]fn test_beginning_end_of_line_ignore_soft_wrap(cx: &mut TestAppContext) {init_test(cx, |_| {});