From fa552f1c476913fb08fd48f9e2bbe2d327551fcc Mon Sep 17 00:00:00 2001 From: Mathieu Agopian Date: Thu, 9 Mar 2023 11:07:45 +0100 Subject: [PATCH] Implement feedback from cargo clippy --- helix-term/src/commands.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 41284aab1..beeb7ea71 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1910,12 +1910,10 @@ fn search_selection(cx: &mut Context) { let (view, doc) = current!(cx.editor); let contents = doc.text().slice(..); - let regex; // The fragment to set in the search register - // Checks whether there is only one selection with a width of 1 let selections = doc.selection(view.id); let primary = selections.primary(); - if selections.len() == 1 && primary.len() == 1 { + let regex = if selections.len() == 1 && primary.len() == 1 { let text = doc.text(); let text_slice = text.slice(..); // In this case select the WORD under the cursor @@ -1927,16 +1925,16 @@ fn search_selection(cx: &mut Context) { false, ); let text_to_search = current_word.fragment(text_slice).to_string(); - regex = regex::escape(&text_to_search); + regex::escape(&text_to_search) } else { - regex = selections + selections .iter() .map(|selection| regex::escape(&selection.fragment(contents))) .collect::>() // Collect into hashset to deduplicate identical regexes .into_iter() .collect::>() - .join("|"); - } + .join("|") + }; let msg = format!("register '{}' set to '{}'", '/', ®ex); cx.editor.registers.push('/', regex); cx.editor.set_status(msg);