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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue