textual icon indicating copy to clipboard operation
textual copied to clipboard

Investigate binding `ctrl+left_square_brace`

Open darrenburns opened this issue 2 years ago • 4 comments

It seems we have support for ctrl+right_square_bracket and ctrl+left_square_brace. Note that we've called it "bracket" in the first binding, and "brace" in the latter.

The bindings for the key alias ctrl+left_square_brace also don't seem to fire.

Also, it seems that changing the alias brace -> bracket doesn't fix the issue - when the bindings are checked, it seems the alias isn't being used.

Not sure if this is relating to the fact that ESC is an alias of the same key.

Basically, there's something fishy with this binding. It doesn't seem to fire and I don't know what the correct behaviour is -- it needs investigation.

darrenburns avatar Jul 27 '23 12:07 darrenburns

Just to add that this seems to be the case for all keys with aliases. If you uncomment the binding for escape below for example, then pressing Ctrl+[ will fire the notification.

from textual.app import App, ComposeResult
from textual.widgets import Footer


class ExampleApp(App):
    BINDINGS = [
        ("ctrl+left_square_brace", "ctrl_left_square_brace", "Miss"),
        # ("escape", "escape", "Fires"),
        ("ctrl+space", "ctrl_space", "Miss"),
        # ("ctrl+@", "ctrl_at", "Fires"),
        ("ctrl+m", "ctrl_m", "Miss"),
        # ("enter", "enter", "Fires"),
    ]

    def compose(self) -> ComposeResult:
        yield Footer()

    def action_ctrl_left_square_brace(self) -> None:
        self.bell()
        self.notify("You pressed ctrl+left_square_brace")

    def action_escape(self) -> None:
        self.bell()
        self.notify("You pressed escape")

    def action_ctrl_space(self) -> None:
        self.bell()
        self.notify("You pressed ctrl+space")

    def action_ctrl_at(self) -> None:
        self.bell()
        self.notify("You pressed ctrl+@")

    def action_ctrl_m(self) -> None:
        self.bell()
        self.notify("You pressed ctrl+m")

    def action_enter(self) -> None:
        self.bell()
        self.notify("You pressed enter")


if __name__ == "__main__":
    app = ExampleApp()
    app.run()

TomJGooding avatar Jul 27 '23 17:07 TomJGooding

Possibly see also #3563.

davep avatar Oct 30 '23 13:10 davep

I don't think this is related to #3563.

If you run textual keys, you can see that the key events fire as expected. This works with current main and the #3563 PR branch.

rndusr avatar Nov 01 '23 11:11 rndusr

The see-also is more of a "there's other key-binding related things going on here too so do check in there" link than anything else.

davep avatar Nov 01 '23 11:11 davep

The ctrl_left_square_brace has been named ctrl_left_square_bracket now. With that change, it works as expected.

ctrl+space is used as a hotkey to switch languages, at least on macOS, so we can't do much about that.

ctrl+m comes through as enter on older terminals, but can be bound on new terminals that support the updated key protocol.

Just some legacy terminal weirdness I'm afraid. Not much can be done about it.

willmcgugan avatar Jul 10 '24 14:07 willmcgugan

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Jul 10 '24 14:07 github-actions[bot]