From 2a8d38c27bce34c9b6fa95a2fb063fe097e220d4 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 18 Jul 2022 09:11:25 +0800 Subject: support toggling pickers' preview panel (#3021) * support toggling pickers' preview panel * add doc for toggling preview--- helix-term/src/ui/picker.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'helix-term') diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 375723e5..9707c81e 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -173,7 +173,7 @@ impl Component for FilePicker { // | | | | // +---------+ +---------+ - let render_preview = area.width > MIN_AREA_WIDTH_FOR_PREVIEW; + let render_preview = self.picker.show_preview && area.width > MIN_AREA_WIDTH_FOR_PREVIEW; // -- Render the frame: // clear area let background = cx.editor.theme.get("ui.background"); @@ -300,6 +300,8 @@ pub struct Picker { previous_pattern: String, /// Whether to truncate the start (default true) pub truncate_start: bool, + /// Whether to show the preview panel (default true) + show_preview: bool, callback_fn: Box, } @@ -327,6 +329,7 @@ impl Picker { prompt, previous_pattern: String::new(), truncate_start: true, + show_preview: true, callback_fn: Box::new(callback_fn), completion_height: 0, }; @@ -470,6 +473,10 @@ impl Picker { self.filters.sort_unstable(); // used for binary search later self.prompt.clear(cx); } + + pub fn toggle_preview(&mut self) { + self.show_preview = !self.show_preview; + } } // process: @@ -538,6 +545,9 @@ impl Component for Picker { ctrl!(' ') => { self.save_filter(cx); } + ctrl!('t') => { + self.toggle_preview(); + } _ => { if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) { // TODO: recalculate only if pattern changed -- cgit v1.2.3-70-g09d2