From 1a465ffd7a9c07e93dbf5e074cfa4746fe7334db 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/dialog.rs b/src/dialog.rs index f398ee1..b8846fe 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -13,11 +13,12 @@ use cosmic::{ keyboard::{Event as KeyEvent, Key, Modifiers}, stream, window, }, + iced_core::widget::operation, theme, widget::{ self, - menu::{Action as MenuAction, KeyBind, key_bind::Modifier}, - segmented_button, + menu::{key_bind::Modifier, Action as MenuAction, KeyBind}, + segmented_button, Operation, }, }; use notify_debouncer_full::{ @@ -1271,6 +1272,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) }