diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cd566720d498..a854376bfce9 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5177,7 +5177,7 @@ fn hover(cx: &mut Context) { // skip if contents empty let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); - let popup = Popup::new("documentation", contents); + let popup = Popup::new("documentation", contents).auto_close(true); if let Some(doc_popup) = compositor.find_id("documentation") { *doc_popup = popup; } else { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 0183918ea84a..1174eae085b0 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -17,6 +17,7 @@ pub struct Popup { size: (u16, u16), child_size: (u16, u16), scroll: usize, + auto_close: bool, id: &'static str, } @@ -28,6 +29,7 @@ impl Popup { size: (0, 0), child_size: (0, 0), scroll: 0, + auto_close: false, id, } } @@ -36,6 +38,11 @@ impl Popup { self.position = pos; } + pub fn auto_close(mut self, auto_close: bool) -> Self { + self.auto_close = auto_close; + self + } + pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) { let position = self .position @@ -119,11 +126,13 @@ impl Component for Popup { _ => { let contents_event_result = self.contents.handle_event(event, cx); - if let EventResult::Ignored(None) = contents_event_result { - EventResult::Ignored(Some(close_fn)) - } else { - contents_event_result + if self.auto_close { + if let EventResult::Ignored(None) = contents_event_result { + return EventResult::Ignored(Some(close_fn)); + } } + + contents_event_result } } // for some events, we want to process them but send ignore, specifically all input except