Skip to content

Commit

Permalink
Fix Shift+Tab behavior when no widget is focused (emilk#3498)
Browse files Browse the repository at this point in the history
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review you PR, but my time is limited!
-->

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.
  • Loading branch information
DataTriny authored Nov 11, 2023
1 parent 59b4eff commit 85e14e8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 85e14e8

Please sign in to comment.