@@ -10,7 +10,7 @@ use helix_core::{
1010use once_cell::sync::Lazy;
1111
1212use crate::compositor::Compositor;
13−use crate::ui::Prompt;
13+use crate::ui::{Prompt, PromptEvent};
1414
1515use helix_view::{
1616 document::Mode,
@@ -262,18 +262,37 @@ pub fn split_selection(cx: &mut Context) {
262262 // # update state
263263 // }
264264
265+ let snapshot = cx.view.doc.state.clone();
266+
265267 let prompt = Prompt::new(
266268 "split:".to_string(),
267269 |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
268− |editor: &mut Editor, input: &str| {
269− match Regex::new(input) {
270− Ok(regex) => {
270+ move |editor: &mut Editor, input: &str, event: PromptEvent| {
271+ match event {
272+ PromptEvent::Abort => {
273+ // revert state
271274 let view = editor.view_mut().unwrap();
272− let text = &view.doc.text().slice(..);
273− let selection = selection::split_on_matches(text, view.doc.selection(), ®ex);
274− view.doc.set_selection(selection);
275+ view.doc.state = snapshot.clone();
276+ }
277+ PromptEvent::Validate => {
278+ //
279+ }
280+ PromptEvent::Update => {
281+ match Regex::new(input) {
282+ Ok(regex) => {
283+ let view = editor.view_mut().unwrap();
284+
285+ // revert state to what it was before the last update
286+ view.doc.state = snapshot.clone();
287+
288+ let text = &view.doc.text().slice(..);
289+ let selection =
290+ selection::split_on_matches(text, view.doc.selection(), ®ex);
291+ view.doc.set_selection(selection);
292+ }
293+ Err(_) => (), // TODO: mark command line as error
294+ }
275295 }
276− Err(_) => (), // TODO: mark command line as error
277296 }
278297 },
279298 );
@@ -416,9 +435,15 @@ pub fn command_mode(cx: &mut Context) {
416435 .filter(|command| command.contains(_input))
417436 .collect()
418437 }, // completion
419− |editor: &mut Editor, input: &str| match input {
420− "q" => editor.should_close = true,
421− _ => (),
438+ |editor: &mut Editor, input: &str, event: PromptEvent| {
439+ if event != PromptEvent::Validate {
440+ return;
441+ }
442+
443+ match input {
444+ "q" => editor.should_close = true,
445+ _ => (),
446+ }
422447 },
423448 );
424449 compositor.push(Box::new(prompt));