From 2472f9909bde9116856036ed94f89374fb376983 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 29 Feb 2024 20:53:15 -0700 Subject: [PATCH] Unfocus grid item on escape --- src/app.rs | 5 +++++ src/tab.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index b35a849..bf98fc9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -677,7 +677,12 @@ impl Application for App { return Command::none(); } + let had_focused_button = tab.select_focus_id().is_some(); if tab.select_none() { + if had_focused_button { + // Unfocus if there was a focused button + return widget::button::focus(widget::Id::unique()); + } return Command::none(); } } diff --git a/src/tab.rs b/src/tab.rs index 78b90a9..8b04014 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -743,7 +743,7 @@ impl Tab { } } - fn select_focus_id(&self) -> Option { + pub fn select_focus_id(&self) -> Option { let items = self.items_opt.as_ref()?; let item = items.get(self.select_focus?)?; Some(item.button_id.clone())