-
Notifications
You must be signed in to change notification settings - Fork 826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try and better settle focus after a focused widget is removed (redux) #954
Conversation
This change ensures that, for example, the widget remains in the Screen.focus_chain so that it's easier to handle passing off focus on removal. To help address Textualize#939.
This makes it easier for me to see which widget is which in the focus chain, etc, when logging.
Addresses the issue raised in Textualize#939. Here I rework Screen._reset_focus so that, rather than deal with siblings, it deals with the focus chain. It now also optionally takes a list of DOMNodes to avoid and will, as that suggests, avoid them when looking for somewhere to move focus to. As a preference the new version of this will seek to settle focus on the nearest (in the chain) *previous* non-excluded DOMNode. NOTE: Currently the return value of Widget.walk_children is cast to a list to ensure that it doesn't get consumed (as of the time of commit, it's still qan iterable). Once Textualize#952 has been accepted I'll change this (remove the cast).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Looks good! Just comments.
|
||
remove_widgets = widget.walk_children( | ||
Widget, with_self=True, method="depth", reverse=True | ||
remove_widgets = list( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove the list
when the other PR is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye, already noted in 11ddcdd on commit.
for candidate in reversed( | ||
focusable_widgets[widget_index + 1 :] + focusable_widgets[:widget_index] | ||
): | ||
if candidate not in avoiding and candidate.can_focus: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can be sure that candidate.can_focus
is True, can't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a 🤦 as the real response here.
As per Textualize#954 (comment) Good catch!
A new approach to solving #939, written to avoid the issues that #943 would have caused.