Add `rotate_selections_{first,last}` commands (#13615)

pull/13702/head
Axlefublr 2025-06-07 04:08:41 +08:00 committed by GitHub
parent 01341cbbf6
commit 637274c4d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -303,3 +303,5 @@
| `extend_to_word` | Extend to a two-character label | select: `` gw `` | | `extend_to_word` | Extend to a two-character label | select: `` gw `` |
| `goto_next_tabstop` | Goto next snippet placeholder | | | `goto_next_tabstop` | Goto next snippet placeholder | |
| `goto_prev_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 | |

View File

@ -601,6 +601,8 @@ impl MappableCommand {
extend_to_word, "Extend to a two-character label", extend_to_word, "Extend to a two-character label",
goto_next_tabstop, "Goto next snippet placeholder", goto_next_tabstop, "Goto next snippet placeholder",
goto_prev_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) 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 { enum ReorderStrategy {
RotateForward, RotateForward,
RotateBackward, RotateBackward,