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 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'helix-term/src/commands.rs') 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)); } // -- cgit v1.2.3-70-g09d2