Skip to content

Support more key combinations in TextArea#6543

Merged
willmcgugan merged 11 commits into
mainfrom
textarea-actions
May 19, 2026
Merged

Support more key combinations in TextArea#6543
willmcgugan merged 11 commits into
mainfrom
textarea-actions

Conversation

@willmcgugan
Copy link
Copy Markdown
Member

@willmcgugan willmcgugan commented May 16, 2026

Fixes #6488

  • ctrl+u doesn't remove previous \n when cursor is at the beginning of the line (but ctrl+k actually has the good behavior regarding \n)
  • ctrl+b: Move cursor backward (left)
  • ctrl+f: Move cursor forward (right) - instead, it currently deletes the next word
  • ctrl+backspace: delete previous word (this one is probably also linked to kitty protocol support)
  • option+delete: Delete end of word
  • ctrl+p: Move cursor to the previous line
  • ctrl+n: Move cursor to the next line
  • Side note: would it make sense to support cmd+Z at the TextArea level?

ctrl+p conflicts with the command palette. Apps that need this can easily add bindings in a subclass. See note in comment

cmd+z is bound as an alternative to ctrl+z. Alas, not all terminals report this. Ghostty captures ctrl+z as undo for its own purposes. The cmd modifier doesn't work at all in iTerm. It does work in Kitty though.

There's not much I can do from the Textual side to improve things here. It is somewhat possible to deduce what bindings are available, then at least the app can not display bindings that don't work. But this typically relies on environment variables being set correctly, and it may fail over ssh, tmux etc.

@willmcgugan willmcgugan marked this pull request as draft May 16, 2026 07:33
@willmcgugan
Copy link
Copy Markdown
Member Author

@mgesbert The ctrl+p shortcut conflicts with the ctrl+p binding for the command palette. Rather than implement 3 out of the 4 navigation shortcuts, its probably best for you to add the bindings to Vibe. I don't think you are using the command palette anyway, so this shouldn't be a problem.

It is trivial to add these bindings. You can add bindings to a TextArea subclass as follows:

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

TEXT = """Hello, world!
foo
bad"""


class VTextArea(widgets.TextArea):
    BINDINGS = [
        Binding(
            "up,ctrl+p",
            "cursor_up",
            "Cursor up",
            show=False,
        ),
        Binding(
            "down,ctrl+n",
            "cursor_down",
            "Cursor down",
            show=False,
        ),
        Binding(
            "left,ctrl+b",
            "cursor_left",
            "Cursor left",
            show=False,
        ),
        Binding(
            "right,ctrl+f",
            "cursor_right",
            "Cursor right",
            show=False,
        ),
    ]


class TApp(App):
    ENABLE_COMMAND_PALETTE = False

    def compose(self) -> ComposeResult:
        yield VTextArea(TEXT)


TApp().run()

@willmcgugan willmcgugan marked this pull request as ready for review May 18, 2026 06:42
@willmcgugan willmcgugan merged commit 3b04f31 into main May 19, 2026
23 checks passed
@willmcgugan willmcgugan deleted the textarea-actions branch May 19, 2026 06:56
@willmcgugan
Copy link
Copy Markdown
Member Author

@mgesbert This is merged. Some relevant notes in the description and comments.

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.

Support more emacs-style keybindings in TextArea

1 participant