aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-15 08:09:18 +0000
committerBlaž Hrastnik2021-03-15 08:09:18 +0000
commitdd91090a1ae931a604c51b9c6d7d8c9b46761af4 (patch)
tree3a399be8dba630a20c84a960e8aeb421c025dbac /helix-term
parent872d77075302a3f5b526045e07e0a5564d170e1b (diff)
Implement keep_selections (filter selections on regex).
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs10
-rw-r--r--helix-term/src/keymap.rs1
2 files changed, 10 insertions, 1 deletions
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(), &regex) {
+ 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,