aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorRobert2023-06-13 13:36:28 +0000
committerGitHub2023-06-13 13:36:28 +0000
commit015c079acc59653390797cbd700fdf7657e220a9 (patch)
treea79389c5dd188c1c9b8430547b54ee2f8a3588f8 /helix-term
parent37fcd160db610feb4a910a3c587cc73a3a2e6635 (diff)
Add reverse_selection_contents (#7329)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 99f27c00..a4f4414a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -406,6 +406,7 @@ impl MappableCommand {
rotate_selections_backward, "Rotate selections backward",
rotate_selection_contents_forward, "Rotate selection contents forward",
rotate_selection_contents_backward, "Rotate selections contents backward",
+ reverse_selection_contents, "Reverse selections contents",
expand_selection, "Expand selection to parent syntax node",
shrink_selection, "Shrink selection to previously expanded syntax node",
select_next_sibling, "Select next sibling in syntax tree",
@@ -4482,7 +4483,13 @@ fn rotate_selections_backward(cx: &mut Context) {
rotate_selections(cx, Direction::Backward)
}
-fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
+enum ReorderStrategy {
+ RotateForward,
+ RotateBackward,
+ Reverse,
+}
+
+fn reorder_selection_contents(cx: &mut Context, strategy: ReorderStrategy) {
let count = cx.count;
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
@@ -4500,9 +4507,10 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
for chunk in fragments.chunks_mut(group) {
// TODO: also modify main index
- match direction {
- Direction::Forward => chunk.rotate_right(1),
- Direction::Backward => chunk.rotate_left(1),
+ match strategy {
+ ReorderStrategy::RotateForward => chunk.rotate_right(1),
+ ReorderStrategy::RotateBackward => chunk.rotate_left(1),
+ ReorderStrategy::Reverse => chunk.reverse(),
};
}
@@ -4519,10 +4527,13 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
}
fn rotate_selection_contents_forward(cx: &mut Context) {
- rotate_selection_contents(cx, Direction::Forward)
+ reorder_selection_contents(cx, ReorderStrategy::RotateForward)
}
fn rotate_selection_contents_backward(cx: &mut Context) {
- rotate_selection_contents(cx, Direction::Backward)
+ reorder_selection_contents(cx, ReorderStrategy::RotateBackward)
+}
+fn reverse_selection_contents(cx: &mut Context) {
+ reorder_selection_contents(cx, ReorderStrategy::Reverse)
}
// tree sitter node selection