Merge pull request #1311 from pop-os/joshmegnauth-dialog-escape

dialog escape
This commit is contained in:
Jeremy Soller 2025-10-23 09:34:13 -06:00 committed by GitHub
commit 419516863c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 256 additions and 246 deletions

479
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -10,12 +10,13 @@ use cosmic::{
core::SmolStr,
event,
futures::{self, SinkExt},
keyboard::{Event as KeyEvent, Key, Modifiers},
keyboard::{Event as KeyEvent, Key, Modifiers, key::Named},
stream, window,
},
iced_core::widget::operation,
theme,
widget::{
self,
self, Operation,
menu::{Action as MenuAction, KeyBind, key_bind::Modifier},
segmented_button,
},
@ -415,6 +416,7 @@ enum Message {
DialogCancel,
DialogComplete,
DialogUpdate(DialogPage),
Escape,
Filename(String),
Filter(usize),
Key(Modifiers, Key, Option<SmolStr>),
@ -1271,6 +1273,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)
}
@ -1337,6 +1347,7 @@ impl Application for App {
self.dialog_pages[0] = dialog_page;
}
}
Message::Escape => return self.on_escape(),
Message::Filename(new_filename) => {
// Select based on filename
self.tab.select_name(&new_filename);
@ -1968,7 +1979,13 @@ impl Application for App {
..
}) => match status {
event::Status::Ignored => Some(Message::Key(modifiers, key, text)),
event::Status::Captured => None,
event::Status::Captured => {
if key == Key::Named(Named::Escape) {
Some(Message::Escape)
} else {
None
}
}
},
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
Some(Message::ModifiersChanged(modifiers))