|
|
|
@ -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::<HashSet<_>>() // Collect into hashset to deduplicate identical regexes
|
|
|
|
|
.into_iter()
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
.join("|");
|
|
|
|
|
}
|
|
|
|
|
.join("|")
|
|
|
|
|
};
|
|
|
|
|
let msg = format!("register '{}' set to '{}'", '/', ®ex);
|
|
|
|
|
cx.editor.registers.push('/', regex);
|
|
|
|
|
cx.editor.set_status(msg);
|
|
|
|
|