mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Allow a count with CurrentLine
Add _ and g_ too while we're here.
This commit is contained in:
parent
b922d0f132
commit
e8a6ecd6ac
2 changed files with 28 additions and 1 deletions
|
@ -32,6 +32,8 @@
|
||||||
"right": "vim::Right",
|
"right": "vim::Right",
|
||||||
"$": "vim::EndOfLine",
|
"$": "vim::EndOfLine",
|
||||||
"^": "vim::FirstNonWhitespace",
|
"^": "vim::FirstNonWhitespace",
|
||||||
|
"_": "vim::StartOfLineDownward",
|
||||||
|
"g _": "vim::EndOfLineDownward",
|
||||||
"shift-g": "vim::EndOfDocument",
|
"shift-g": "vim::EndOfDocument",
|
||||||
"w": "vim::NextWordStart",
|
"w": "vim::NextWordStart",
|
||||||
"{": "vim::StartOfParagraph",
|
"{": "vim::StartOfParagraph",
|
||||||
|
|
|
@ -40,6 +40,8 @@ pub enum Motion {
|
||||||
FindForward { before: bool, char: char },
|
FindForward { before: bool, char: char },
|
||||||
FindBackward { after: bool, char: char },
|
FindBackward { after: bool, char: char },
|
||||||
NextLineStart,
|
NextLineStart,
|
||||||
|
StartOfLineDownward,
|
||||||
|
EndOfLineDownward,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
|
@ -117,6 +119,8 @@ actions!(
|
||||||
EndOfDocument,
|
EndOfDocument,
|
||||||
Matching,
|
Matching,
|
||||||
NextLineStart,
|
NextLineStart,
|
||||||
|
StartOfLineDownward,
|
||||||
|
EndOfLineDownward,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
impl_actions!(
|
impl_actions!(
|
||||||
|
@ -207,6 +211,12 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx: _| { motion(Motion::PreviousWordStart { ignore_punctuation }, cx) },
|
cx: _| { motion(Motion::PreviousWordStart { ignore_punctuation }, cx) },
|
||||||
);
|
);
|
||||||
cx.add_action(|_: &mut Workspace, &NextLineStart, cx: _| motion(Motion::NextLineStart, cx));
|
cx.add_action(|_: &mut Workspace, &NextLineStart, cx: _| motion(Motion::NextLineStart, cx));
|
||||||
|
cx.add_action(|_: &mut Workspace, &StartOfLineDownward, cx: _| {
|
||||||
|
motion(Motion::StartOfLineDownward, cx)
|
||||||
|
});
|
||||||
|
cx.add_action(|_: &mut Workspace, &EndOfLineDownward, cx: _| {
|
||||||
|
motion(Motion::EndOfLineDownward, cx)
|
||||||
|
});
|
||||||
cx.add_action(|_: &mut Workspace, action: &RepeatFind, cx: _| {
|
cx.add_action(|_: &mut Workspace, action: &RepeatFind, cx: _| {
|
||||||
repeat_motion(action.backwards, cx)
|
repeat_motion(action.backwards, cx)
|
||||||
})
|
})
|
||||||
|
@ -272,6 +282,7 @@ impl Motion {
|
||||||
| EndOfDocument
|
| EndOfDocument
|
||||||
| CurrentLine
|
| CurrentLine
|
||||||
| NextLineStart
|
| NextLineStart
|
||||||
|
| StartOfLineDownward
|
||||||
| StartOfParagraph
|
| StartOfParagraph
|
||||||
| EndOfParagraph => true,
|
| EndOfParagraph => true,
|
||||||
EndOfLine { .. }
|
EndOfLine { .. }
|
||||||
|
@ -282,6 +293,7 @@ impl Motion {
|
||||||
| Backspace
|
| Backspace
|
||||||
| Right
|
| Right
|
||||||
| StartOfLine { .. }
|
| StartOfLine { .. }
|
||||||
|
| EndOfLineDownward
|
||||||
| NextWordStart { .. }
|
| NextWordStart { .. }
|
||||||
| PreviousWordStart { .. }
|
| PreviousWordStart { .. }
|
||||||
| FirstNonWhitespace { .. }
|
| FirstNonWhitespace { .. }
|
||||||
|
@ -305,6 +317,8 @@ impl Motion {
|
||||||
| StartOfLine { .. }
|
| StartOfLine { .. }
|
||||||
| StartOfParagraph
|
| StartOfParagraph
|
||||||
| EndOfParagraph
|
| EndOfParagraph
|
||||||
|
| StartOfLineDownward
|
||||||
|
| EndOfLineDownward
|
||||||
| NextWordStart { .. }
|
| NextWordStart { .. }
|
||||||
| PreviousWordStart { .. }
|
| PreviousWordStart { .. }
|
||||||
| FirstNonWhitespace { .. }
|
| FirstNonWhitespace { .. }
|
||||||
|
@ -322,6 +336,7 @@ impl Motion {
|
||||||
| EndOfDocument
|
| EndOfDocument
|
||||||
| CurrentLine
|
| CurrentLine
|
||||||
| EndOfLine { .. }
|
| EndOfLine { .. }
|
||||||
|
| EndOfLineDownward
|
||||||
| NextWordEnd { .. }
|
| NextWordEnd { .. }
|
||||||
| Matching
|
| Matching
|
||||||
| FindForward { .. }
|
| FindForward { .. }
|
||||||
|
@ -330,6 +345,7 @@ impl Motion {
|
||||||
| Backspace
|
| Backspace
|
||||||
| Right
|
| Right
|
||||||
| StartOfLine { .. }
|
| StartOfLine { .. }
|
||||||
|
| StartOfLineDownward
|
||||||
| StartOfParagraph
|
| StartOfParagraph
|
||||||
| EndOfParagraph
|
| EndOfParagraph
|
||||||
| NextWordStart { .. }
|
| NextWordStart { .. }
|
||||||
|
@ -396,7 +412,7 @@ impl Motion {
|
||||||
map.clip_at_line_end(movement::end_of_paragraph(map, point, times)),
|
map.clip_at_line_end(movement::end_of_paragraph(map, point, times)),
|
||||||
SelectionGoal::None,
|
SelectionGoal::None,
|
||||||
),
|
),
|
||||||
CurrentLine => (end_of_line(map, false, point), SelectionGoal::None),
|
CurrentLine => (next_line_end(map, point, 1), SelectionGoal::None),
|
||||||
StartOfDocument => (start_of_document(map, point, times), SelectionGoal::None),
|
StartOfDocument => (start_of_document(map, point, times), SelectionGoal::None),
|
||||||
EndOfDocument => (
|
EndOfDocument => (
|
||||||
end_of_document(map, point, maybe_times),
|
end_of_document(map, point, maybe_times),
|
||||||
|
@ -412,6 +428,8 @@ impl Motion {
|
||||||
SelectionGoal::None,
|
SelectionGoal::None,
|
||||||
),
|
),
|
||||||
NextLineStart => (next_line_start(map, point, times), SelectionGoal::None),
|
NextLineStart => (next_line_start(map, point, times), SelectionGoal::None),
|
||||||
|
StartOfLineDownward => (next_line_start(map, point, times - 1), SelectionGoal::None),
|
||||||
|
EndOfLineDownward => (next_line_end(map, point, times), SelectionGoal::None),
|
||||||
};
|
};
|
||||||
|
|
||||||
(new_point != point || infallible).then_some((new_point, goal))
|
(new_point != point || infallible).then_some((new_point, goal))
|
||||||
|
@ -849,6 +867,13 @@ fn next_line_start(map: &DisplaySnapshot, point: DisplayPoint, times: usize) ->
|
||||||
first_non_whitespace(map, false, correct_line)
|
first_non_whitespace(map, false, correct_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_line_end(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> DisplayPoint {
|
||||||
|
if times > 1 {
|
||||||
|
point = down(map, point, SelectionGoal::None, times - 1).0;
|
||||||
|
}
|
||||||
|
end_of_line(map, false, point)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
|
|
Loading…
Reference in a new issue