diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 18a02e9773b3952d99b71f6d337f3c8950aff78e..bec381506060435419e86727051cda53ab220316 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, ) { + 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, ) { + 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.rs index fe71cb76f0f16dc7a928ccff725585c0e857c62e..0da80a2a73f22afac7085b579494d708be2444a4 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, |_| {});