on master help sign in
Add reverse_selection_contents (#7329)
015c079Robert
helix-term/src/commands.rs+17−6
@@ -406,6 +406,7 @@ impl MappableCommand {
406 rotate_selections_backward, "Rotate selections backward",
406 rotate_selections_backward, "Rotate selections backward",
407 rotate_selection_contents_forward, "Rotate selection contents forward",
407 rotate_selection_contents_forward, "Rotate selection contents forward",
408 rotate_selection_contents_backward, "Rotate selections contents backward",
408 rotate_selection_contents_backward, "Rotate selections contents backward",
409+ reverse_selection_contents, "Reverse selections contents",
409 expand_selection, "Expand selection to parent syntax node",
410 expand_selection, "Expand selection to parent syntax node",
410 shrink_selection, "Shrink selection to previously expanded syntax node",
411 shrink_selection, "Shrink selection to previously expanded syntax node",
411 select_next_sibling, "Select next sibling in syntax tree",
412 select_next_sibling, "Select next sibling in syntax tree",
@@ -4482,7 +4483,13 @@ fn rotate_selections_backward(cx: &mut Context) {
4482 rotate_selections(cx, Direction::Backward)
4483 rotate_selections(cx, Direction::Backward)
4483}
4484}
4484
4485
4485−fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4486+enum ReorderStrategy {
4487+ RotateForward,
4488+ RotateBackward,
4489+ Reverse,
4490+}
4491+
4492+fn reorder_selection_contents(cx: &mut Context, strategy: ReorderStrategy) {
4486 let count = cx.count;
4493 let count = cx.count;
4487 let (view, doc) = current!(cx.editor);
4494 let (view, doc) = current!(cx.editor);
4488 let text = doc.text().slice(..);
4495 let text = doc.text().slice(..);
@@ -4500,9 +4507,10 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4500
4507
4501 for chunk in fragments.chunks_mut(group) {
4508 for chunk in fragments.chunks_mut(group) {
4502 // TODO: also modify main index
4509 // TODO: also modify main index
4503− match direction {
4510+ match strategy {
4504− Direction::Forward => chunk.rotate_right(1),
4511+ ReorderStrategy::RotateForward => chunk.rotate_right(1),
4505− Direction::Backward => chunk.rotate_left(1),
4512+ ReorderStrategy::RotateBackward => chunk.rotate_left(1),
4513+ ReorderStrategy::Reverse => chunk.reverse(),
4506 };
4514 };
4507 }
4515 }
4508
4516
@@ -4519,10 +4527,13 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4519}
4527}
4520
4528
4521fn rotate_selection_contents_forward(cx: &mut Context) {
4529fn rotate_selection_contents_forward(cx: &mut Context) {
4522− rotate_selection_contents(cx, Direction::Forward)
4530+ reorder_selection_contents(cx, ReorderStrategy::RotateForward)
4523}
4531}
4524fn rotate_selection_contents_backward(cx: &mut Context) {
4532fn rotate_selection_contents_backward(cx: &mut Context) {
4525− rotate_selection_contents(cx, Direction::Backward)
4533+ reorder_selection_contents(cx, ReorderStrategy::RotateBackward)
4534+}
4535+fn reverse_selection_contents(cx: &mut Context) {
4536+ reorder_selection_contents(cx, ReorderStrategy::Reverse)
4526}
4537}
4527
4538
4528// tree sitter node selection
4539// tree sitter node selection