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

popup: close popup on escape press. #6978

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions internal/common/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ macro_rules! for_each_enums {

// This enum describes the close behaviour of [`PopupWindow`](elements.md#popupwindow)
enum PopupClosePolicy {
/// Closes the `PopupWindow` when user clicks.
/// Closes the `PopupWindow` when user clicks or presses the escape key.
CloseOnClick,

/// Closed the `PopupWindow` when user clicks outside of the popup.
/// Closed the `PopupWindow` when user clicks outside of the popup or presses the escape key.
FloVanGH marked this conversation as resolved.
Show resolved Hide resolved
CloseOnClickOutside,

/// Does not close the `PopupWindow` automatically when user clicks
/// Does not close the `PopupWindow` automatically when user clicks.
NoAutoClose,
}
];
Expand Down
15 changes: 15 additions & 0 deletions internal/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,21 @@ impl WindowInner {

event.modifiers = self.modifiers.get().into();

// Closes top most popup on esc key pressed when policy is not no-auto-close
if event.event_type == KeyEventType::KeyPressed && event.text.starts_with(key_codes::Escape)
{
let close_on_escape = if let Some(popup) = self.active_popups.borrow().last() {
popup.close_policy == PopupClosePolicy::CloseOnClick
|| popup.close_policy == PopupClosePolicy::CloseOnClickOutside
} else {
false
};

if close_on_escape {
self.close_top_popup();
}
}

let mut item = self.focus_item.borrow().clone().upgrade();
while let Some(focus_item) = item {
if !focus_item.is_visible() {
Expand Down
Loading