Add stop_at_indent
for MoveToBeginningOfLine (#25428)
Add support for `stop_at_indent` option for MoveToBeginningOfLine and SelectToBeginningOfLine instead of mixing that with `stop_at_soft_wraps`. Add emacs mapping for `alt-m` (`back-to-indentation`)
This commit is contained in:
parent
3a3621f2d8
commit
eebee4ab18
11 changed files with 40 additions and 16 deletions
|
@ -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": {
|
||||
|
|
|
@ -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",
|
||||
|
@ -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 }],
|
||||
|
|
|
@ -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 }],
|
||||
|
@ -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 }],
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,6 +22,8 @@ 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)]
|
||||
|
@ -29,6 +31,8 @@ pub struct MoveToBeginningOfLine {
|
|||
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)]
|
||||
|
|
|
@ -9371,7 +9371,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,
|
||||
)
|
||||
});
|
||||
|
@ -9387,7 +9392,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,
|
||||
)
|
||||
});
|
||||
|
@ -9410,6 +9420,7 @@ impl Editor {
|
|||
this.select_to_beginning_of_line(
|
||||
&SelectToBeginningOfLine {
|
||||
stop_at_soft_wraps: false,
|
||||
stop_at_indent: false,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
|
@ -1034,6 +1034,7 @@ impl ProjectPanel {
|
|||
editor.move_to_beginning_of_line(
|
||||
&editor::actions::MoveToBeginningOfLine {
|
||||
stop_at_soft_wraps: false,
|
||||
stop_at_indent: false,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
|
|
|
@ -188,7 +188,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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue