on master help sign in
prompt: make the callback a FnOnce.
1a843b6Blaž Hrastnik
helix-term/src/commands.rs+15−16
@@ -262,24 +262,23 @@ pub fn split_selection(cx: &mut Context) {
262 // # update state
262 // # update state
263 // }
263 // }
264
264
265− cx.callback = Some(Box::new(|compositor: &mut Compositor| {
266− let prompt = Prompt::new(
265+ let prompt = Prompt::new(
267− "split:".to_string(),
266+ "split:".to_string(),
268− |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
267+ |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
269− |editor: &mut Editor, input: &str| {
268+ |editor: &mut Editor, input: &str| {
270− match Regex::new(input) {
269+ match Regex::new(input) {
271− Ok(regex) => {
270+ Ok(regex) => {
272− let view = editor.view_mut().unwrap();
271+ let view = editor.view_mut().unwrap();
273− let text = &view.doc.text().slice(..);
272+ let text = &view.doc.text().slice(..);
274− let selection =
275− selection::split_on_matches(text, view.doc.selection(), &regex);
273+ let selection = selection::split_on_matches(text, view.doc.selection(), &regex);
276− view.doc.set_selection(selection);
274+ view.doc.set_selection(selection);
277− }
278− Err(_) => (), // TODO: mark command line as error
279 }
275 }
276+ Err(_) => (), // TODO: mark command line as error
280− },
277+ }
278+ },
281− );
279+ );
282
280
281+ cx.callback = Some(Box::new(move |compositor: &mut Compositor| {
283 compositor.push(Box::new(prompt));
282 compositor.push(Box::new(prompt));
284 }));
283 }));
285}
284}
helix-term/src/compositor.rs+1−1
@@ -19,7 +19,7 @@ use smol::Executor;
19use tui::buffer::Buffer as Surface;
19use tui::buffer::Buffer as Surface;
20use tui::layout::Rect;
20use tui::layout::Rect;
21
21
22−pub type Callback = Box<dyn Fn(&mut Compositor)>;
22+pub type Callback = Box<dyn FnOnce(&mut Compositor)>;
23
23
24// --> EventResult should have a callback that takes a context with methods like .popup(),
24// --> EventResult should have a callback that takes a context with methods like .popup(),
25// .prompt() etc. That way we can abstract it from the renderer.
25// .prompt() etc. That way we can abstract it from the renderer.