diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4cded7ef8cbd7..1272cc8a126a6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2921,7 +2921,7 @@ pub mod cmd { let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); - let popup = Popup::new("hover", contents); + let popup = Popup::new("hover", contents).auto_close(true); compositor.replace_or_push("hover", Box::new(popup)); }); Ok(call) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index af11cd4e98cbf..798dedc688fe6 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -633,7 +633,7 @@ pub fn hover(cx: &mut Context) { // skip if contents empty let contents = ui::Markdown::new(contents, editor.syn_loader.clone()); - let popup = Popup::new("hover", contents); + let popup = Popup::new("hover", contents).auto_close(true); compositor.replace_or_push("hover", Box::new(popup)); } }, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 03bd834a48e66..7deedb25cca5c 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -884,7 +884,7 @@ impl EditorView { } } - EventResult::Ignored + EventResult::Ignored(None) } MouseEvent { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 812c73a7b03f8..455274822442e 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -18,6 +18,7 @@ pub struct Popup { size: (u16, u16), child_size: (u16, u16), scroll: usize, + auto_close: bool, id: &'static str, } @@ -33,6 +34,7 @@ impl Popup { size: (0, 0), child_size: (0, 0), scroll: 0, + auto_close: false, id, } } @@ -46,6 +48,11 @@ impl Popup { self } + 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 @@ -129,11 +136,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