|
|
@ -10,7 +10,7 @@ use helix_core::{
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::compositor::Compositor;
|
|
|
|
use crate::compositor::Compositor;
|
|
|
|
use crate::ui::Prompt;
|
|
|
|
use crate::ui::{Prompt, PromptEvent};
|
|
|
|
|
|
|
|
|
|
|
|
use helix_view::{
|
|
|
|
use helix_view::{
|
|
|
|
document::Mode,
|
|
|
|
document::Mode,
|
|
|
@ -262,19 +262,38 @@ pub fn split_selection(cx: &mut Context) {
|
|
|
|
// # update state
|
|
|
|
// # update state
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let snapshot = cx.view.doc.state.clone();
|
|
|
|
|
|
|
|
|
|
|
|
let prompt = Prompt::new(
|
|
|
|
let prompt = Prompt::new(
|
|
|
|
"split:".to_string(),
|
|
|
|
"split:".to_string(),
|
|
|
|
|input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
|
|
|
|
|input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
|
|
|
|
|editor: &mut Editor, input: &str| {
|
|
|
|
move |editor: &mut Editor, input: &str, event: PromptEvent| {
|
|
|
|
|
|
|
|
match event {
|
|
|
|
|
|
|
|
PromptEvent::Abort => {
|
|
|
|
|
|
|
|
// revert state
|
|
|
|
|
|
|
|
let view = editor.view_mut().unwrap();
|
|
|
|
|
|
|
|
view.doc.state = snapshot.clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PromptEvent::Validate => {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PromptEvent::Update => {
|
|
|
|
match Regex::new(input) {
|
|
|
|
match Regex::new(input) {
|
|
|
|
Ok(regex) => {
|
|
|
|
Ok(regex) => {
|
|
|
|
let view = editor.view_mut().unwrap();
|
|
|
|
let view = editor.view_mut().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// revert state to what it was before the last update
|
|
|
|
|
|
|
|
view.doc.state = snapshot.clone();
|
|
|
|
|
|
|
|
|
|
|
|
let text = &view.doc.text().slice(..);
|
|
|
|
let text = &view.doc.text().slice(..);
|
|
|
|
let selection = selection::split_on_matches(text, view.doc.selection(), ®ex);
|
|
|
|
let selection =
|
|
|
|
|
|
|
|
selection::split_on_matches(text, view.doc.selection(), ®ex);
|
|
|
|
view.doc.set_selection(selection);
|
|
|
|
view.doc.set_selection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(_) => (), // TODO: mark command line as error
|
|
|
|
Err(_) => (), // TODO: mark command line as error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -416,9 +435,15 @@ pub fn command_mode(cx: &mut Context) {
|
|
|
|
.filter(|command| command.contains(_input))
|
|
|
|
.filter(|command| command.contains(_input))
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}, // completion
|
|
|
|
}, // completion
|
|
|
|
|editor: &mut Editor, input: &str| match input {
|
|
|
|
|editor: &mut Editor, input: &str, event: PromptEvent| {
|
|
|
|
|
|
|
|
if event != PromptEvent::Validate {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match input {
|
|
|
|
"q" => editor.should_close = true,
|
|
|
|
"q" => editor.should_close = true,
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
compositor.push(Box::new(prompt));
|
|
|
|
compositor.push(Box::new(prompt));
|
|
|
|