Skip to content

Commit

Permalink
Use OR of all selections in search_selection command (helix-editor#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanVasko authored and thomasskk committed Sep 9, 2022
1 parent a380cc1 commit 79be4cb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,10 +1751,16 @@ fn extend_search_prev(cx: &mut Context) {
fn search_selection(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let contents = doc.text().slice(..);
let query = doc.selection(view.id).primary().fragment(contents);
let regex = regex::escape(&query);

let regex = doc
.selection(view.id)
.iter()
.map(|selection| regex::escape(&selection.fragment(contents)))
.collect::<Vec<_>>()
.join("|");

let msg = format!("register '{}' set to '{}'", '/', &regex);
cx.editor.registers.get_mut('/').push(regex);
let msg = format!("register '{}' set to '{}'", '/', query);
cx.editor.set_status(msg);
}

Expand Down

0 comments on commit 79be4cb

Please sign in to comment.