diff --git a/book/src/generated/static-cmd.md b/book/src/generated/static-cmd.md index fa9123219..7ecb7f4e8 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 446337411..2cbdeb451 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,