on master help sign in
Resume last picker
eba0bbdIvan Tham
helix-term/src/commands.rs+14
@@ -217,6 +217,7 @@ impl Command {
217 file_picker,
217 file_picker,
218 buffer_picker,
218 buffer_picker,
219 symbol_picker,
219 symbol_picker,
220+ last_picker,
220 prepend_to_line,
221 prepend_to_line,
221 append_to_line,
222 append_to_line,
222 open_below,
223 open_below,
@@ -2091,6 +2092,17 @@ fn symbol_picker(cx: &mut Context) {
2091 )
2092 )
2092}
2093}
2093
2094
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+
2094// I inserts at the first nonwhitespace character of each line with a selection
2106// I inserts at the first nonwhitespace character of each line with a selection
2095fn prepend_to_line(cx: &mut Context) {
2107fn prepend_to_line(cx: &mut Context) {
2096 goto_first_nonwhitespace(cx);
2108 goto_first_nonwhitespace(cx);
@@ -3749,6 +3761,8 @@ macro_rules! mode_info {
3749mode_info! {
3761mode_info! {
3750 /// space mode
3762 /// space mode
3751 space_mode, SPACE_MODE,
3763 space_mode, SPACE_MODE,
3764+ /// resume last picker
3765+ "'" => last_picker,
3752 /// file picker
3766 /// file picker
3753 "f" => file_picker,
3767 "f" => file_picker,
3754 /// buffer picker
3768 /// buffer picker
helix-term/src/compositor.rs+5−2
@@ -74,6 +74,8 @@ type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
74pub struct Compositor {
74pub struct Compositor {
75 layers: Vec<Box<dyn Component>>,
75 layers: Vec<Box<dyn Component>>,
76 terminal: Terminal,
76 terminal: Terminal,
77+
78+ pub(crate) last_picker: Option<Box<dyn Component>>,
77}
79}
78
80
79impl Compositor {
81impl Compositor {
@@ -83,6 +85,7 @@ impl Compositor {
83 Ok(Self {
85 Ok(Self {
84 layers: Vec::new(),
86 layers: Vec::new(),
85 terminal,
87 terminal,
88+ last_picker: None,
86 })
89 })
87 }
90 }
88
91
@@ -103,8 +106,8 @@ impl Compositor {
103 self.layers.push(layer);
106 self.layers.push(layer);
104 }
107 }
105
108
106− pub fn pop(&mut self) {
109+ pub fn pop(&mut self) -> Option<Box<dyn Component>> {
107− self.layers.pop();
110+ self.layers.pop()
108 }
111 }
109
112
110 pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool {
113 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> {
159
159
160 let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
160 let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
161 // remove the layer
161 // remove the layer
162− compositor.pop();
162+ compositor.last_picker = compositor.pop();
163 })));
163 })));
164
164
165 match key_event {
165 match key_event {