Skip to content
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

Merged
merged 4 commits into from
Oct 19, 2022

Conversation

davep
Copy link
Contributor

@davep davep commented Oct 19, 2022

A new approach to solving #939, written to avoid the issues that #943 would have caused.

davep added 4 commits October 19, 2022 10:44
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).
Copy link
Collaborator

@willmcgugan willmcgugan left a 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(
Copy link
Collaborator

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.

Copy link
Contributor Author

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@davep davep merged commit 84e514e into Textualize:css Oct 19, 2022
@davep davep deleted the bug/939/loss-of-focus-take-2 branch October 19, 2022 14:35
davep added a commit to davep/textual that referenced this pull request Oct 19, 2022
willmcgugan added a commit that referenced this pull request Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants