From a23b70182c5c714fb6210be7e6d4f4e3b15b0e8f Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 10 Jul 2023 19:09:26 -0500 Subject: [PATCH] commands: Allow using selected register where hardcoded These snippets use hardcoded registers but it can be useful to be able to specify a register for these commands. --- helix-term/src/commands.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d9ea580d..329b7ab7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1908,9 +1908,10 @@ fn searcher(cx: &mut Context, direction: Direction) { fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) { let count = cx.count(); + let register = cx.register.unwrap_or('/'); let config = cx.editor.config(); let scrolloff = config.scrolloff; - if let Some(query) = cx.editor.registers.last('/', cx.editor) { + if let Some(query) = cx.editor.registers.last(register, cx.editor) { let doc = doc!(cx.editor); let contents = doc.text().slice(..).to_string(); let search_config = &config.search; @@ -1960,6 +1961,7 @@ fn extend_search_prev(cx: &mut Context) { } fn search_selection(cx: &mut Context) { + let register = cx.register.unwrap_or('/'); let (view, doc) = current!(cx.editor); let contents = doc.text().slice(..); @@ -1972,15 +1974,16 @@ fn search_selection(cx: &mut Context) { .collect::>() .join("|"); - let msg = format!("register '{}' set to '{}'", '/', ®ex); - match cx.editor.registers.push('/', regex) { + let msg = format!("register '{}' set to '{}'", register, ®ex); + match cx.editor.registers.push(register, regex) { Ok(_) => cx.editor.set_status(msg), Err(err) => cx.editor.set_error(err.to_string()), } } fn make_search_word_bounded(cx: &mut Context) { - let regex = match cx.editor.registers.last('/', cx.editor) { + let register = cx.register.unwrap_or('/'); + let regex = match cx.editor.registers.last(register, cx.editor) { Some(regex) => regex, None => return, }; @@ -2003,8 +2006,8 @@ fn make_search_word_bounded(cx: &mut Context) { new_regex.push_str("\\b"); } - let msg = format!("register '{}' set to '{}'", '/', &new_regex); - match cx.editor.registers.push('/', new_regex) { + let msg = format!("register '{}' set to '{}'", register, &new_regex); + match cx.editor.registers.push(register, new_regex) { Ok(_) => cx.editor.set_status(msg), Err(err) => cx.editor.set_error(err.to_string()), }