Skip to content

Close dialog on esc if text input is focused #973

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use cosmic::{
keyboard::{Event as KeyEvent, Key, Modifiers},
mouse, stream, window, Alignment, Event, Length, Point, Size, Subscription,
},
iced_core::widget::operation,
theme,
widget::{
self,
menu::{key_bind::Modifier, Action as MenuAction, KeyBind},
segmented_button,
segmented_button, Operation,
},
Application, ApplicationExt, Element,
};
Expand Down Expand Up @@ -1177,6 +1178,14 @@ impl Application for App {
return Task::none();
}

// Close the dialog if the focused widget is the dialog's main text input instead of
// unfocussing the widget.
if let operation::Outcome::Some(focused) = operation::focusable::find_focused().finish() {
if self.dialog_text_input == focused {
return self.update(Message::Cancel);
}
}

self.update(Message::Cancel)
}

Expand Down