From 85e14e89bd08654b03c318f18e6a98410e5f315a Mon Sep 17 00:00:00 2001 From: Arnold Loubriat Date: Sat, 11 Nov 2023 09:16:38 +0100 Subject: [PATCH] Fix Shift+Tab behavior when no widget is focused (#3498) If no widget is focused (such as when an application just started or after Escape was pressed), pressing Shift+Tab does not set the focus to the last widget. I think this PR fixes that. --- crates/egui/src/memory.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 2c56d967248..908d9f7bb7c 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -415,6 +415,13 @@ impl Focus { // nothing has focus and the user pressed tab - give focus to the first widgets that wants it: self.focused_widget = Some(FocusWidget::new(id)); self.reset_focus(); + } else if self.focus_direction == FocusDirection::Previous + && self.focused_widget.is_none() + && !self.give_to_next + { + // nothing has focus and the user pressed Shift+Tab - give focus to the last widgets that wants it: + self.focused_widget = self.last_interested.map(FocusWidget::new); + self.reset_focus(); } self.last_interested = Some(id);