Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle mouse events based on pointer focus for popups #10126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,29 @@ impl<T: Component> Popup<T> {
&& y < self.area.bottom();

if !mouse_is_within_popup {
return EventResult::Ignored(None);
return EventResult::Ignored(Some(self.close_cb()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite sure how I feel about closing popups without giving their contents a chance to cleanup.

I think we should emulate a c-c press here so the popup gets a chance to cleanup

Suggested change
return EventResult::Ignored(Some(self.close_cb()));
let _ = self.contents.handle_event(ctrl!(c), cx)
return EventResult::Ignored(Some(self.close_cb()));

}

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 {
Box::new(|compositor, _| {
// remove the layer
compositor.remove(self.id.as_ref());
})
}
}

Expand All @@ -231,16 +240,11 @@ impl<T: Component> Component for Popup<T> {
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();
Expand All @@ -255,7 +259,7 @@ impl<T: Component> Component for Popup<T> {

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()));
}
}

Expand Down
Loading