From dd91090a1ae931a604c51b9c6d7d8c9b46761af4 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 15 Mar 2021 17:09:18 +0900 Subject: Implement keep_selections (filter selections on regex). --- helix-term/src/commands.rs | 10 +++++++++- helix-term/src/keymap.rs | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'helix-term/src') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 36edde4c..d75fd694 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1156,7 +1156,15 @@ pub fn join_selections(cx: &mut Context) { pub fn keep_selections(cx: &mut Context) { let doc = cx.doc(); // keep selections matching regex - // and another method for inverse + let prompt = ui::regex_prompt(cx, "keep:".to_string(), |doc, regex| { + let text = doc.text().slice(..); + + if let Some(selection) = selection::keep_matches(text, doc.selection(), ®ex) { + doc.set_selection(selection); + } + }); + + cx.push_layer(Box::new(prompt)); } // diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 58a465fe..a365050f 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -207,6 +207,7 @@ pub fn default() -> Keymaps { key!('<') => commands::unindent, key!('=') => commands::format_selections, shift!('J') => commands::join_selections, + // TODO: conflicts hover/doc shift!('K') => commands::keep_selections, // key!('q') => commands::record_macro, -- cgit v1.2.3-70-g09d2