on master help sign in
prompt: make the callback a FnOnce.
commit1a843b6c06b5d4d75feb0a424bbfdcfb33ab7651 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 15 Dec 2020, 19:07 (6 years ago) parent2bfdced
2 files changed+16−17
helix-term/src/commands.rs+15−16 helix-term/src/compositor.rs+1−1
helix-term/src/commands.rs+15−16
@@ -262,24 +262,23 @@ pub fn split_selection(cx: &mut Context) {
262262 // # update state
263263 // }
264264
265− cx.callback = Some(Box::new(|compositor: &mut Compositor| {
266− let prompt = Prompt::new(
267− "split:".to_string(),
268− |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
269− |editor: &mut Editor, input: &str| {
270− match Regex::new(input) {
271− Ok(regex) => {
272− let view = editor.view_mut().unwrap();
273− let text = &view.doc.text().slice(..);
274− let selection =
275− selection::split_on_matches(text, view.doc.selection(), &regex);
276− view.doc.set_selection(selection);
277− }
278− Err(_) => (), // TODO: mark command line as error
265+ let prompt = Prompt::new(
266+ "split:".to_string(),
267+ |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) => {
271+ let view = editor.view_mut().unwrap();
272+ let text = &view.doc.text().slice(..);
273+ let selection = selection::split_on_matches(text, view.doc.selection(), &regex);
274+ view.doc.set_selection(selection);
279275 }
280− },
281− );
276+ Err(_) => (), // TODO: mark command line as error
277+ }
278+ },
279+ );
282280
281+ cx.callback = Some(Box::new(move |compositor: &mut Compositor| {
283282 compositor.push(Box::new(prompt));
284283 }));
285284}
helix-term/src/compositor.rs+1−1
@@ -19,7 +19,7 @@ use smol::Executor;
1919use tui::buffer::Buffer as Surface;
2020use tui::layout::Rect;
2121
22−pub type Callback = Box<dyn Fn(&mut Compositor)>;
22+pub type Callback = Box<dyn FnOnce(&mut Compositor)>;
2323
2424// --> EventResult should have a callback that takes a context with methods like .popup(),
2525// .prompt() etc. That way we can abstract it from the renderer.