Unnamed repository; edit this file 'description' to name the repository.
Add `rotate_selections_{first,last}` commands (#13615)
Axlefublr 9 months ago
parent 01341cb · commit 637274c
-rw-r--r--book/src/generated/static-cmd.md2
-rw-r--r--helix-term/src/commands.rs17
2 files changed, 19 insertions, 0 deletions
diff --git a/book/src/generated/static-cmd.md b/book/src/generated/static-cmd.md
index fa912321..7ecb7f4e 100644
--- a/book/src/generated/static-cmd.md
+++ b/book/src/generated/static-cmd.md
@@ -303,3 +303,5 @@
| `extend_to_word` | Extend to a two-character label | select: `` gw `` |
| `goto_next_tabstop` | Goto next snippet placeholder | |
| `goto_prev_tabstop` | Goto next snippet placeholder | |
+| `rotate_selections_first` | Make the first selection your primary one | |
+| `rotate_selections_last` | Make the last selection your primary one | |
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 44633741..2cbdeb45 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -601,6 +601,8 @@ impl MappableCommand {
extend_to_word, "Extend to a two-character label",
goto_next_tabstop, "Goto next snippet placeholder",
goto_prev_tabstop, "Goto next snippet placeholder",
+ rotate_selections_first, "Make the first selection your primary one",
+ rotate_selections_last, "Make the last selection your primary one",
);
}
@@ -5292,6 +5294,21 @@ fn rotate_selections_backward(cx: &mut Context) {
rotate_selections(cx, Direction::Backward)
}
+fn rotate_selections_first(cx: &mut Context) {
+ let (view, doc) = current!(cx.editor);
+ let mut selection = doc.selection(view.id).clone();
+ selection.set_primary_index(0);
+ doc.set_selection(view.id, selection);
+}
+
+fn rotate_selections_last(cx: &mut Context) {
+ let (view, doc) = current!(cx.editor);
+ let mut selection = doc.selection(view.id).clone();
+ let len = selection.len();
+ selection.set_primary_index(len - 1);
+ doc.set_selection(view.id, selection);
+}
+
enum ReorderStrategy {
RotateForward,
RotateBackward,