mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-30 00:35:26 +03:00
commands: Stop select_regex from breaking when no matches.
This commit is contained in:
parent
a21d96e729
commit
4c6611f96b
@ -307,11 +307,9 @@ pub fn select_all(cx: &mut Context) {
|
||||
pub fn select_regex(cx: &mut Context) {
|
||||
let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
|
||||
let text = doc.text().slice(..);
|
||||
// TODO: if select on matches returns empty range, we need to abort
|
||||
// if regex empty or no matches, return
|
||||
let selection =
|
||||
selection::select_on_matches(text, doc.selection(), ®ex).expect("no matches");
|
||||
doc.set_selection(selection);
|
||||
if let Some(selection) = selection::select_on_matches(text, doc.selection(), ®ex) {
|
||||
doc.set_selection(selection);
|
||||
}
|
||||
});
|
||||
|
||||
cx.push_layer(Box::new(prompt));
|
||||
|
@ -45,6 +45,11 @@ pub fn regex_prompt(
|
||||
//
|
||||
}
|
||||
PromptEvent::Update => {
|
||||
// skip empty input, TODO: trigger default
|
||||
if input.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
match Regex::new(input) {
|
||||
Ok(regex) => {
|
||||
let view = &mut editor.view_mut();
|
||||
|
Loading…
Reference in New Issue
Block a user