aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorIvan Tham2022-02-07 15:37:09 +0000
committerBlaž Hrastnik2022-04-02 15:46:53 +0000
commit8b02bf2ea8c07926697ad8e1e01d77596a540d59 (patch)
treec05a6d37077ff414c972ca2f3b5b34c7d171446a /helix-term/src/commands.rs
parente4561d1ddede65baaaf04adf5baa0edbaf8f8028 (diff)
Add (prev) paragraph motion
Also improved testing facility. Fix #1580
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 29648039..beb564ad 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -209,6 +209,8 @@ impl MappableCommand {
move_next_long_word_start, "Move to beginning of next long word",
move_prev_long_word_start, "Move to beginning of previous long word",
move_next_long_word_end, "Move to end of next long word",
+ move_prev_para, "Move to previous paragraph",
+ move_next_para, "Move to next paragraph",
extend_next_word_start, "Extend to beginning of next word",
extend_prev_word_start, "Extend to beginning of previous word",
extend_next_long_word_start, "Extend to beginning of next long word",
@@ -902,6 +904,34 @@ fn move_next_long_word_end(cx: &mut Context) {
move_word_impl(cx, movement::move_next_long_word_end)
}
+fn move_para_impl<F>(cx: &mut Context, move_fn: F)
+where
+ F: Fn(RopeSlice, Range, usize, Movement) -> Range,
+{
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ let text = doc.text().slice(..);
+ let behavior = if doc.mode == Mode::Select {
+ Movement::Extend
+ } else {
+ Movement::Move
+ };
+
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| move_fn(text, range, count, behavior));
+ doc.set_selection(view.id, selection);
+}
+
+fn move_prev_para(cx: &mut Context) {
+ move_para_impl(cx, movement::move_prev_para)
+}
+
+fn move_next_para(cx: &mut Context) {
+ move_para_impl(cx, movement::move_next_para)
+}
+
fn goto_file_start(cx: &mut Context) {
if cx.count.is_some() {
goto_line(cx);