Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop_at_indent for MoveToBeginningOfLine #25428

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
},
"JSON": {
"tab_size": 2,
"preferred_line_length": 100,
"preferred_line_length": 120,
"formatter": "prettier"
},
"JSONC": {
"tab_size": 2,
"preferred_line_length": 100,
"preferred_line_length": 120,
"formatter": "prettier"
},
"JavaScript": {
Expand Down
8 changes: 4 additions & 4 deletions assets/keymaps/default-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"pageup": "editor::MovePageUp",
"alt-pageup": "editor::PageUp",
"shift-pageup": "editor::SelectPageUp",
"home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true }],
"home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"down": "editor::MoveDown",
"pagedown": "editor::MovePageDown",
"alt-pagedown": "editor::PageDown",
Expand All @@ -107,9 +107,9 @@
"ctrl-a": "editor::SelectAll",
"ctrl-l": "editor::SelectLine",
"ctrl-shift-i": "editor::Format",
// "cmd-shift-left": ["editor::SelectToBeginningOfLine", {"stop_at_soft_wraps": true }],
// "ctrl-shift-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true }],
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true }],
// "cmd-shift-left": ["editor::SelectToBeginningOfLine", {"stop_at_soft_wraps": true, "stop_at_indent": true }],
// "ctrl-shift-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
// "cmd-shift-right": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
// "ctrl-shift-e": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
Expand Down
12 changes: 6 additions & 6 deletions assets/keymaps/default-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
"ctrl-l": "editor::ScrollCursorCenter",
"alt-left": "editor::MoveToPreviousWordStart",
"alt-right": "editor::MoveToNextWordEnd",
"cmd-left": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true }],
"ctrl-a": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false }],
"home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true }],
"cmd-left": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"ctrl-a": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }],
"home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"cmd-right": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": true }],
"ctrl-e": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }],
"end": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": true }],
Expand All @@ -118,9 +118,9 @@
"cmd-a": "editor::SelectAll",
"cmd-l": "editor::SelectLine",
"cmd-shift-i": "editor::Format",
"cmd-shift-left": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true }],
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true }],
"ctrl-shift-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true }],
"cmd-shift-left": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"ctrl-shift-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"cmd-shift-right": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
"ctrl-shift-e": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
Expand Down
1 change: 1 addition & 0 deletions assets/keymaps/linux/emacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ctrl-e": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
"alt-m": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }], // back-to-indentation
"alt-f": "editor::MoveToNextSubwordEnd", // forward-word
"alt-b": "editor::MoveToPreviousSubwordStart", // backward-word
"alt-u": "editor::ConvertToUpperCase", // upcase-word
Expand Down
1 change: 1 addition & 0 deletions assets/keymaps/macos/emacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ctrl-e": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
"alt-m": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }], // back-to-indentation
"alt-f": "editor::MoveToNextSubwordEnd", // forward-word
"alt-b": "editor::MoveToPreviousSubwordStart", // backward-word
"alt-u": "editor::ConvertToUpperCase", // upcase-word
Expand Down
4 changes: 4 additions & 0 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ pub struct SelectPrevious {
pub struct MoveToBeginningOfLine {
#[serde(default = "default_true")]
pub stop_at_soft_wraps: bool,
#[serde(default)]
pub stop_at_indent: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SelectToBeginningOfLine {
#[serde(default)]
pub(super) stop_at_soft_wraps: bool,
#[serde(default)]
pub stop_at_indent: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
Expand Down
15 changes: 13 additions & 2 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8827,7 +8827,12 @@ impl Editor {
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_cursors_with(|map, head, _| {
(
movement::indented_line_beginning(map, head, action.stop_at_soft_wraps),
movement::indented_line_beginning(
map,
head,
action.stop_at_soft_wraps,
action.stop_at_indent,
),
SelectionGoal::None,
)
});
Expand All @@ -8843,7 +8848,12 @@ impl Editor {
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_heads_with(|map, head, _| {
(
movement::indented_line_beginning(map, head, action.stop_at_soft_wraps),
movement::indented_line_beginning(
map,
head,
action.stop_at_soft_wraps,
action.stop_at_indent,
),
SelectionGoal::None,
)
});
Expand All @@ -8866,6 +8876,7 @@ impl Editor {
this.select_to_beginning_of_line(
&SelectToBeginningOfLine {
stop_at_soft_wraps: false,
stop_at_indent: false,
},
window,
cx,
Expand Down
5 changes: 5 additions & 0 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let move_to_beg = MoveToBeginningOfLine {
stop_at_soft_wraps: true,
stop_at_indent: true,
};

let move_to_end = MoveToEndOfLine {
Expand Down Expand Up @@ -1590,6 +1591,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {
editor.select_to_beginning_of_line(
&SelectToBeginningOfLine {
stop_at_soft_wraps: true,
stop_at_indent: true,
},
window,
cx,
Expand All @@ -1607,6 +1609,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {
editor.select_to_beginning_of_line(
&SelectToBeginningOfLine {
stop_at_soft_wraps: true,
stop_at_indent: true,
},
window,
cx,
Expand All @@ -1624,6 +1627,7 @@ fn test_beginning_end_of_line(cx: &mut TestAppContext) {
editor.select_to_beginning_of_line(
&SelectToBeginningOfLine {
stop_at_soft_wraps: true,
stop_at_indent: true,
},
window,
cx,
Expand Down Expand Up @@ -1684,6 +1688,7 @@ fn test_beginning_end_of_line_ignore_soft_wrap(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let move_to_beg = MoveToBeginningOfLine {
stop_at_soft_wraps: false,
stop_at_indent: false,
};

let move_to_end = MoveToEndOfLine {
Expand Down
3 changes: 2 additions & 1 deletion crates/editor/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub fn indented_line_beginning(
map: &DisplaySnapshot,
display_point: DisplayPoint,
stop_at_soft_boundaries: bool,
stop_at_indent: bool,
) -> DisplayPoint {
let point = display_point.to_point(map);
let soft_line_start = map.clip_point(DisplayPoint::new(display_point.row(), 0), Bias::Right);
Expand All @@ -229,7 +230,7 @@ pub fn indented_line_beginning(
if stop_at_soft_boundaries && soft_line_start > indent_start && display_point != soft_line_start
{
soft_line_start
} else if stop_at_soft_boundaries && display_point != indent_start {
} else if stop_at_indent && display_point != indent_start {
indent_start
} else {
line_start
Expand Down
1 change: 1 addition & 0 deletions crates/project_panel/src/project_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ impl ProjectPanel {
editor.move_to_beginning_of_line(
&editor::actions::MoveToBeginningOfLine {
stop_at_soft_wraps: false,
stop_at_indent: false,
},
window,
cx,
Expand Down
2 changes: 1 addition & 1 deletion crates/vim/src/normal/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Vim {
)
.0;
}
cursor = movement::indented_line_beginning(map, cursor, true);
cursor = movement::indented_line_beginning(map, cursor, true, true);
} else if !is_multiline && !vim.temp_mode {
cursor = movement::saturating_left(map, cursor)
}
Expand Down
Loading