Skip to content

Commit 5c72983

Browse files
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.
1 parent 6447af4 commit 5c72983

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/dialog.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use cosmic::{
1010
keyboard::{Event as KeyEvent, Key, Modifiers},
1111
mouse, stream, window, Alignment, Event, Length, Point, Size, Subscription,
1212
},
13+
iced_core::widget::operation,
1314
theme,
1415
widget::{
1516
self,
1617
menu::{key_bind::Modifier, Action as MenuAction, KeyBind},
17-
segmented_button,
18+
segmented_button, Operation,
1819
},
1920
Application, ApplicationExt, Element,
2021
};
@@ -1177,6 +1178,13 @@ impl Application for App {
11771178
return Task::none();
11781179
}
11791180

1181+
// Close the dialog if the focused widget is the dialog's main text input instead of
1182+
// unfocussing the widget.
1183+
let focused = operation::focusable::find_focused().finish();
1184+
if (self.dialog_text_input == focused) {
1185+
return self.update(Message::Cancel);
1186+
}
1187+
11801188
self.update(Message::Cancel)
11811189
}
11821190

0 commit comments

Comments
 (0)