on master help sign in
Resume last picker

Inspired by space ' in doom emacs.

commiteba0bbda2ee10e9ba53f01f1d324d2c4c82229d2 authorIvan Tham <pickfire@riseup.net> dateSun 18 Jul 2021, 12:24 (5 years ago) parentdf0ed80
3 files changed+20−3
helix-term/src/commands.rs+14 helix-term/src/compositor.rs+5−2 helix-term/src/ui/picker.rs+1−1
helix-term/src/commands.rs+14
@@ -217,6 +217,7 @@ impl Command {
217217 file_picker,
218218 buffer_picker,
219219 symbol_picker,
220+ last_picker,
220221 prepend_to_line,
221222 append_to_line,
222223 open_below,
@@ -2091,6 +2092,17 @@ fn symbol_picker(cx: &mut Context) {
20912092 )
20922093}
20932094
2095+fn last_picker(cx: &mut Context) {
2096+ // TODO: last picker does not seemed to work well with buffer_picker
2097+ cx.callback = Some(Box::new(|compositor: &mut Compositor| {
2098+ if let Some(picker) = compositor.last_picker.take() {
2099+ compositor.push(picker);
2100+ }
2101+ // XXX: figure out how to show error when no last picker lifetime
2102+ // cx.editor.set_error("no last picker".to_owned())
2103+ }));
2104+}
2105+
20942106// I inserts at the first nonwhitespace character of each line with a selection
20952107fn prepend_to_line(cx: &mut Context) {
20962108 goto_first_nonwhitespace(cx);
@@ -3749,6 +3761,8 @@ macro_rules! mode_info {
37493761mode_info! {
37503762 /// space mode
37513763 space_mode, SPACE_MODE,
3764+ /// resume last picker
3765+ "'" => last_picker,
37523766 /// file picker
37533767 "f" => file_picker,
37543768 /// buffer picker
helix-term/src/compositor.rs+5−2
@@ -74,6 +74,8 @@ type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
7474pub struct Compositor {
7575 layers: Vec<Box<dyn Component>>,
7676 terminal: Terminal,
77+
78+ pub(crate) last_picker: Option<Box<dyn Component>>,
7779}
7880
7981impl Compositor {
@@ -83,6 +85,7 @@ impl Compositor {
8385 Ok(Self {
8486 layers: Vec::new(),
8587 terminal,
88+ last_picker: None,
8689 })
8790 }
8891
@@ -103,8 +106,8 @@ impl Compositor {
103106 self.layers.push(layer);
104107 }
105108
106− pub fn pop(&mut self) {
107− self.layers.pop();
109+ pub fn pop(&mut self) -> Option<Box<dyn Component>> {
110+ self.layers.pop()
108111 }
109112
110113 pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool {
helix-term/src/ui/picker.rs+1−1
@@ -159,7 +159,7 @@ impl<T: 'static> Component for Picker<T> {
159159
160160 let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
161161 // remove the layer
162− compositor.pop();
162+ compositor.last_picker = compositor.pop();
163163 })));
164164
165165 match key_event {