Skip to content

Commit

Permalink
Make search_selection and make_search_word_bounded use register s…
Browse files Browse the repository at this point in the history
…election
  • Loading branch information
xJonathanLEI committed Dec 21, 2022
1 parent 2a22d7c commit 452abc2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,8 @@ fn search_selection(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let contents = doc.text().slice(..);

let reg = cx.register.unwrap_or('/');

let regex = doc
.selection(view.id)
.iter()
Expand All @@ -1809,13 +1811,19 @@ fn search_selection(cx: &mut Context) {
.collect::<Vec<_>>()
.join("|");

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

fn make_search_word_bounded(cx: &mut Context) {
let regex = match cx.editor.registers.last('/') {
// Defaults to the active search register instead `/` to be more ergonomic assuming most people
// would use this command following `search_selection`. This avoids selecting the register
// twice.
let reg = cx.register.unwrap_or(cx.editor.search_register);

let regex = match cx.editor.registers.last(reg) {
Some(regex) => regex,
None => return,
};
Expand All @@ -1838,8 +1846,9 @@ fn make_search_word_bounded(cx: &mut Context) {
new_regex.push_str("\\b");
}

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

Expand Down

0 comments on commit 452abc2

Please sign in to comment.