aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-06 02:22:01 +0000
committerBlaž Hrastnik2021-08-06 02:22:01 +0000
commit66a90130a5f99d769e9f6034025297f78ecaa3ec (patch)
tree0e18d71cc3d5ad60cf05955810a81b28da90406a /helix-term/src/commands.rs
parent953125d3f381880f288afa2b59f9936e76d534fa (diff)
Implement selection rotation with `(` and `)`
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 622a3ebd..7facb556 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -275,6 +275,8 @@ impl Command {
completion, "Invoke completion popup",
hover, "Show docs for item under cursor",
toggle_comments, "Comment/uncomment selections",
+ rotate_selections_forward, "Rotate selections forward",
+ rotate_selections_backward, "Rotate selections backward",
expand_selection, "Expand selection to parent syntax node",
jump_forward, "Jump forward on jumplist",
jump_backward, "Jump backward on jumplist",
@@ -3747,6 +3749,25 @@ fn toggle_comments(cx: &mut Context) {
doc.append_changes_to_history(view.id);
}
+fn rotate_selections(cx: &mut Context, direction: Direction) {
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ let mut selection = doc.selection(view.id).clone();
+ let index = selection.primary_index();
+ let len = selection.len();
+ selection.set_primary_index(match direction {
+ Direction::Forward => (index + count) % len,
+ Direction::Backward => (index + (len.saturating_sub(count) % len)) % len,
+ });
+ doc.set_selection(view.id, selection);
+}
+fn rotate_selections_forward(cx: &mut Context) {
+ rotate_selections(cx, Direction::Forward)
+}
+fn rotate_selections_backward(cx: &mut Context) {
+ rotate_selections(cx, Direction::Backward)
+}
+
// tree sitter node selection
fn expand_selection(cx: &mut Context) {