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

BINDINGS in Link should be BINDINGS = [Binding("enter", "focused.open_link", "Open link")]? #5564

Closed
python-and-novella opened this issue Feb 20, 2025 · 6 comments · Fixed by #5567

Comments

@python-and-novella
Copy link
Contributor

python-and-novella commented Feb 20, 2025

BINDINGS = [Binding("enter", "select", "Open link")]

Maybe BINDINGS = [Binding("enter", "focused.open_link", "Open link")] is right.
Then I can press enter to open link.

Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@python-and-novella python-and-novella changed the title BINDINGS in Link should be BINDINGS = [Binding("enter", "open_link", "Open link")]? BINDINGS in Link should be BINDINGS = [Binding("enter", "focused.open_link", "Open link")]? Feb 20, 2025
@TomJGooding
Copy link
Contributor

TomJGooding commented Feb 20, 2025

Good catch! This looks like a simple fix, but I'm wondering why you changed this to focused.open_link rather than simply open_link?

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

1 similar comment
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@python-and-novella
Copy link
Contributor Author

python-and-novella commented Feb 21, 2025

@TomJGooding I‘m writing a chinese guide of Textual. But I am not very familiar with Textual.
So, in #5451, I don't understand the namespace of button's action.
In order that the action of link will be executed successfully, I think focused must be right.

@TomJGooding
Copy link
Contributor

You don't need to add a focused namespace for bindings:

When you press a key, Textual will first check for a matching binding in the BINDINGS list of the currently focused widget. If no match is found, it will search upwards through the DOM all the way up to the App looking for a match.

I've never actually used the action param of the Button, but from a quick look at the code this behaves differently as by calling the action from the app:

if self.action is None:
self.post_message(Button.Pressed(self))
else:
self.call_later(
self.app.run_action, self.action, default_namespace=self._parent
)

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 a pull request may close this issue.

2 participants