aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorMatouš Dzivjak2021-12-29 09:17:46 +0000
committerGitHub2021-12-29 09:17:46 +0000
commitbd2ab5be4331a2ab6d406378a9c0868eb2f72819 (patch)
tree04c09c72eea533540a1d3d1abd191b640a6a9ad0 /helix-term/src/commands.rs
parentdc1faa35cbb92231c037241d01e25ae18ac36176 (diff)
feat(commands): ensure_selections_forward (#1393)
* feat(commands): ensure_selections_forward Add command that ensures that selections are in forward direction. Fixes: https://github.com/helix-editor/helix/issues/1332 * Add keybinding for ensure_selections_forward Add `A-:` keybinding for the ensure_selections_forward command. * Re-use range.flip for flip_selections command
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 04dd222b..9c1650b8 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -266,6 +266,7 @@ impl MappableCommand {
change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
collapse_selection, "Collapse selection onto a single cursor",
flip_selections, "Flip selection cursor and anchor",
+ ensure_selections_forward, "Ensure the selection is in forward direction",
insert_mode, "Insert before selection",
append_mode, "Insert after selection (append)",
command_mode, "Enter command mode",
@@ -1904,7 +1905,21 @@ fn flip_selections(cx: &mut Context) {
let selection = doc
.selection(view.id)
.clone()
- .transform(|range| Range::new(range.head, range.anchor));
+ .transform(|range| range.flip());
+ doc.set_selection(view.id, selection);
+}
+
+fn ensure_selections_forward(cx: &mut Context) {
+ let (view, doc) = current!(cx.editor);
+
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|r| match r.direction() {
+ Direction::Forward => r,
+ Direction::Backward => r.flip(),
+ });
+
doc.set_selection(view.id, selection);
}