diff options
author | Blaž Hrastnik | 2020-12-15 10:07:25 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-12-15 10:07:48 +0000 |
commit | 1a843b6c06b5d4d75feb0a424bbfdcfb33ab7651 (patch) | |
tree | 2f0b77e9fe94368fad33f310c8260bf8aabd2a21 /helix-term/src | |
parent | 2bfdcede32586af01e1e7cda686a48525e0154bd (diff) |
prompt: make the callback a FnOnce.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 31 | ||||
-rw-r--r-- | helix-term/src/compositor.rs | 2 |
2 files changed, 16 insertions, 17 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3db112d3..e49c780a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -262,24 +262,23 @@ pub fn split_selection(cx: &mut Context) { // # update state // } - cx.callback = Some(Box::new(|compositor: &mut Compositor| { - let prompt = Prompt::new( - "split:".to_string(), - |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate - |editor: &mut Editor, input: &str| { - match Regex::new(input) { - Ok(regex) => { - let view = editor.view_mut().unwrap(); - let text = &view.doc.text().slice(..); - let selection = - selection::split_on_matches(text, view.doc.selection(), ®ex); - view.doc.set_selection(selection); - } - Err(_) => (), // TODO: mark command line as error + let prompt = Prompt::new( + "split:".to_string(), + |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate + |editor: &mut Editor, input: &str| { + match Regex::new(input) { + Ok(regex) => { + let view = editor.view_mut().unwrap(); + let text = &view.doc.text().slice(..); + let selection = selection::split_on_matches(text, view.doc.selection(), ®ex); + view.doc.set_selection(selection); } - }, - ); + Err(_) => (), // TODO: mark command line as error + } + }, + ); + cx.callback = Some(Box::new(move |compositor: &mut Compositor| { compositor.push(Box::new(prompt)); })); } diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 2e65f02a..f0d94dbc 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -19,7 +19,7 @@ use smol::Executor; use tui::buffer::Buffer as Surface; use tui::layout::Rect; -pub type Callback = Box<dyn Fn(&mut Compositor)>; +pub type Callback = Box<dyn FnOnce(&mut Compositor)>; // --> EventResult should have a callback that takes a context with methods like .popup(), // .prompt() etc. That way we can abstract it from the renderer. |