|
|
@ -1910,12 +1910,10 @@ fn search_selection(cx: &mut Context) {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let contents = doc.text().slice(..);
|
|
|
|
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
|
|
|
|
// Checks whether there is only one selection with a width of 1
|
|
|
|
let selections = doc.selection(view.id);
|
|
|
|
let selections = doc.selection(view.id);
|
|
|
|
let primary = selections.primary();
|
|
|
|
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 = doc.text();
|
|
|
|
let text_slice = text.slice(..);
|
|
|
|
let text_slice = text.slice(..);
|
|
|
|
// In this case select the WORD under the cursor
|
|
|
|
// In this case select the WORD under the cursor
|
|
|
@ -1927,16 +1925,16 @@ fn search_selection(cx: &mut Context) {
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let text_to_search = current_word.fragment(text_slice).to_string();
|
|
|
|
let text_to_search = current_word.fragment(text_slice).to_string();
|
|
|
|
regex = regex::escape(&text_to_search);
|
|
|
|
regex::escape(&text_to_search)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
regex = selections
|
|
|
|
selections
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|selection| regex::escape(&selection.fragment(contents)))
|
|
|
|
.map(|selection| regex::escape(&selection.fragment(contents)))
|
|
|
|
.collect::<HashSet<_>>() // Collect into hashset to deduplicate identical regexes
|
|
|
|
.collect::<HashSet<_>>() // Collect into hashset to deduplicate identical regexes
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("|");
|
|
|
|
.join("|")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let msg = format!("register '{}' set to '{}'", '/', ®ex);
|
|
|
|
let msg = format!("register '{}' set to '{}'", '/', ®ex);
|
|
|
|
cx.editor.registers.push('/', regex);
|
|
|
|
cx.editor.registers.push('/', regex);
|
|
|
|
cx.editor.set_status(msg);
|
|
|
|
cx.editor.set_status(msg);
|
|
|
|