editor: Skip stop_at_indent for single-line editors (#50681)

In single-line editors like the Find bar, MoveToBeginningOfLine with
stop_at_indent should go directly to column 0 instead of stopping at the
indentation level.

Closes #50634

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zedindustries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed `MoveToBeginningOfLine` stopping at indentation in single-line
editors like the Find bar instead of moving to column 0.
This commit is contained in:
Viraj Bhartiya authored and GitHub committed 2026-03-12 18:28:21 +02:00
1 parent 75ef896828
commit e28dd5d590
2 files changed
+54 -2

No files matched your search

+4 -2
View File
@@ -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,
)
+50
View File
@@ -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, |_| {});