prompt: make the callback a FnOnce.

pull/7/head
Blaž Hrastnik 4 years ago
parent 2bfdcede32
commit 1a843b6c06

@ -262,7 +262,6 @@ pub fn split_selection(cx: &mut Context) {
// # update state // # update state
// } // }
cx.callback = Some(Box::new(|compositor: &mut Compositor| {
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
@ -271,8 +270,7 @@ pub fn split_selection(cx: &mut Context) {
Ok(regex) => { Ok(regex) => {
let view = editor.view_mut().unwrap(); let view = editor.view_mut().unwrap();
let text = &view.doc.text().slice(..); let text = &view.doc.text().slice(..);
let selection = let selection = selection::split_on_matches(text, view.doc.selection(), &regex);
selection::split_on_matches(text, view.doc.selection(), &regex);
view.doc.set_selection(selection); view.doc.set_selection(selection);
} }
Err(_) => (), // TODO: mark command line as error Err(_) => (), // TODO: mark command line as error
@ -280,6 +278,7 @@ pub fn split_selection(cx: &mut Context) {
}, },
); );
cx.callback = Some(Box::new(move |compositor: &mut Compositor| {
compositor.push(Box::new(prompt)); compositor.push(Box::new(prompt));
})); }));
} }

@ -19,7 +19,7 @@ use smol::Executor;
use tui::buffer::Buffer as Surface; use tui::buffer::Buffer as Surface;
use tui::layout::Rect; 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(), // --> EventResult should have a callback that takes a context with methods like .popup(),
// .prompt() etc. That way we can abstract it from the renderer. // .prompt() etc. That way we can abstract it from the renderer.

Loading…
Cancel
Save