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

A Keymap binding that is the same as a BINDING binding will break with symbol keys #5704

Open
TomJGooding opened this issue Apr 3, 2025 · 2 comments · May be fixed by #5700
Open

A Keymap binding that is the same as a BINDING binding will break with symbol keys #5704

TomJGooding opened this issue Apr 3, 2025 · 2 comments · May be fixed by #5700

Comments

@TomJGooding
Copy link
Contributor

TomJGooding commented Apr 3, 2025

I have a similar problem that is probably related: applying a keymap containing a symbol key (like "?" or "/") will cause the keybinding to fail. Logging the value of app.active_bindings showed that before applying a keymap the key's value was "question" and after applying the keymap it was "?".

Here is a modified version of @davep 's code above to illustrate:

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Button, Footer

class BadMapApp(App[None]):
    BINDINGS = [
        Binding("f1", "good", description="Good", id="good"),
        Binding("?", "bad", description="Bad", id="bad"),
    ]

    def compose(self) -> ComposeResult:
        yield Button("Break bad")
        yield Footer()

    def action_good(self) -> None:
        self.notify("Good")

    def action_bad(self) -> None:
        self.notify("Bad")

    def on_button_pressed(self) -> None:
        self.update_keymap({"bad": "?"})
        self.notify("? will no longer work now")

if __name__ == "__main__":
    BadMapApp().run()

Originally posted by @mathman1618 in #5694

Copy link

github-actions bot commented Apr 3, 2025

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

TomJGooding added a commit to TomJGooding/textual that referenced this issue Apr 3, 2025
Extract the code that converts a key binding string into a list of key
values to a separate function, to ensure consistent key handling when
applying keymaps.

Fixes Textualize#5704
@TomJGooding TomJGooding linked a pull request Apr 3, 2025 that will close this issue
3 tasks
@mathman1618
Copy link

Thanks for moving this to a new issue, @TomJGooding . I posted it in #5694 thinking that they had the same root problem, namely, that key strings from Keymaps are not preprocessed in the same way that key strings from Bindings are. Thanks also for making a PR so quickly!

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