From eea339545cf7198b7a9e477ee2a9ee081ee5be36 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 15 Mar 2021 17:13:36 +0900 Subject: Add command for keeping only the primary selection. --- helix-term/src/commands.rs | 8 ++++++++ helix-term/src/keymap.rs | 3 +++ 2 files changed, 11 insertions(+) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d75fd694..507e5be6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1167,6 +1167,14 @@ pub fn keep_selections(cx: &mut Context) { cx.push_layer(Box::new(prompt)); } +pub fn keep_primary_selection(cx: &mut Context) { + let doc = cx.doc(); + + let range = doc.selection().primary(); + let selection = Selection::single(range.anchor, range.head); + doc.set_selection(selection); +} + // pub fn save(cx: &mut Context) { diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index a365050f..35b83b1a 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -209,6 +209,9 @@ pub fn default() -> Keymaps { shift!('J') => commands::join_selections, // TODO: conflicts hover/doc shift!('K') => commands::keep_selections, + // TODO: and another method for inverse + + key!(' ') => commands::keep_primary_selection, // key!('q') => commands::record_macro, // key!('Q') => commands::replay_macro, -- cgit v1.2.3-70-g09d2