on master help sign in
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.

commita23b70182c5c714fb6210be7e6d4f4e3b15b0e8f authorMichael Davis <mcarsondavis@gmail.com> dateMon 10 Jul 2023, 19:09 (3 years ago) parentbaceb02
1 file changed+9−6
helix-term/src/commands.rs+9−6
helix-term/src/commands.rs+9−6
@@ -1908,9 +1908,10 @@ fn searcher(cx: &mut Context, direction: Direction) {
19081908
19091909fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) {
19101910 let count = cx.count();
1911+ let register = cx.register.unwrap_or('/');
19111912 let config = cx.editor.config();
19121913 let scrolloff = config.scrolloff;
1913− if let Some(query) = cx.editor.registers.last('/', cx.editor) {
1914+ if let Some(query) = cx.editor.registers.last(register, cx.editor) {
19141915 let doc = doc!(cx.editor);
19151916 let contents = doc.text().slice(..).to_string();
19161917 let search_config = &config.search;
@@ -1960,6 +1961,7 @@ fn extend_search_prev(cx: &mut Context) {
19601961}
19611962
19621963fn search_selection(cx: &mut Context) {
1964+ let register = cx.register.unwrap_or('/');
19631965 let (view, doc) = current!(cx.editor);
19641966 let contents = doc.text().slice(..);
19651967
@@ -1972,15 +1974,16 @@ fn search_selection(cx: &mut Context) {
19721974 .collect::<Vec<_>>()
19731975 .join("|");
19741976
1975− let msg = format!("register '{}' set to '{}'", '/', &regex);
1976− match cx.editor.registers.push('/', regex) {
1977+ let msg = format!("register '{}' set to '{}'", register, &regex);
1978+ match cx.editor.registers.push(register, regex) {
19771979 Ok(_) => cx.editor.set_status(msg),
19781980 Err(err) => cx.editor.set_error(err.to_string()),
19791981 }
19801982}
19811983
19821984fn make_search_word_bounded(cx: &mut Context) {
1983− let regex = match cx.editor.registers.last('/', cx.editor) {
1985+ let register = cx.register.unwrap_or('/');
1986+ let regex = match cx.editor.registers.last(register, cx.editor) {
19841987 Some(regex) => regex,
19851988 None => return,
19861989 };
@@ -2003,8 +2006,8 @@ fn make_search_word_bounded(cx: &mut Context) {
20032006 new_regex.push_str("\\b");
20042007 }
20052008
2006− let msg = format!("register '{}' set to '{}'", '/', &new_regex);
2007− match cx.editor.registers.push('/', new_regex) {
2009+ let msg = format!("register '{}' set to '{}'", register, &new_regex);
2010+ match cx.editor.registers.push(register, new_regex) {
20082011 Ok(_) => cx.editor.set_status(msg),
20092012 Err(err) => cx.editor.set_error(err.to_string()),
20102013 }