From 9cc0f82e62c68f15c89273fb6cec60bf87809461 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sun, 31 Mar 2024 01:41:08 +0530 Subject: [PATCH 1/3] Extract popup close callback into separate function --- helix-term/src/ui/popup.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 4f379b4a1d5b..abc3e6c32820 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -213,6 +213,13 @@ impl Popup { _ => EventResult::Ignored(None), } } + + fn close_cb(&self) -> Callback { + Box::new(|compositor, _| { + // remove the layer + compositor.remove(self.id.as_ref()); + }) + } } impl Component for Popup { @@ -231,16 +238,11 @@ impl Component for Popup { return EventResult::Ignored(None); } - let close_fn: Callback = Box::new(|compositor, _| { - // remove the layer - compositor.remove(self.id.as_ref()); - }); - match key { // esc or ctrl-c aborts the completion and closes the menu key!(Esc) | ctrl!('c') => { let _ = self.contents.handle_event(event, cx); - EventResult::Consumed(Some(close_fn)) + EventResult::Consumed(Some(self.close_cb())) } ctrl!('d') => { self.scroll_half_page_down(); @@ -255,7 +257,7 @@ impl Component for Popup { if self.auto_close { if let EventResult::Ignored(None) = contents_event_result { - return EventResult::Ignored(Some(close_fn)); + return EventResult::Ignored(Some(self.close_cb())); } } From d05cc257946922e11cde0676935233ec5f90c1ad Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sun, 31 Mar 2024 01:44:44 +0530 Subject: [PATCH 2/3] Close popups when receiving mouse events outside the frame --- helix-term/src/ui/popup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index abc3e6c32820..4c8c1ebd9281 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -198,7 +198,7 @@ impl Popup { && y < self.area.bottom(); if !mouse_is_within_popup { - return EventResult::Ignored(None); + return EventResult::Ignored(Some(self.close_cb())); } match kind { From a97bf79cf79cddfca4453bc8604552a99af1499b Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sun, 31 Mar 2024 01:51:56 +0530 Subject: [PATCH 3/3] Consume all mouse events inside popups Fixes issues of mouse clicks "bleeding" through into the editor when clicked on top of popups. In previous versions, mouse events were ignored and passed into the lower layers which resulted in editor cursor being moved when popup areas are clicked. --- helix-term/src/ui/popup.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 4c8c1ebd9281..93018e08c646 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -204,14 +204,16 @@ impl Popup { match kind { MouseEventKind::ScrollDown if self.has_scrollbar => { self.scroll_half_page_down(); - EventResult::Consumed(None) } MouseEventKind::ScrollUp if self.has_scrollbar => { self.scroll_half_page_up(); - EventResult::Consumed(None) } - _ => EventResult::Ignored(None), - } + _ => {} + }; + + // Mouse event happened within the popup; consume the event so that + // it doesn't bleed into the editor. + EventResult::Consumed(None) } fn close_cb(&self) -> Callback {