From 0ba288092ff7274be426745e2cff9fba20071945 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Thu, 8 May 2025 01:12:14 -0400 Subject: [PATCH] Close dialog on esc if text input is focused Closes: pop-os/cosmic-edit#350 Escape unfocusses the main text input widget instead of closing the dialog. The user has to hit escape twice to close the window. It's not a big deal, but it's also unexpected and unergonomic. --- src/dialog.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dialog.rs b/src/dialog.rs index d5573917..b3e010e1 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -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, }; @@ -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) }