Support more key combinations in TextArea#6543
Merged
Merged
Conversation
Member
Author
|
@mgesbert The 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() |
Member
Author
|
@mgesbert This is merged. Some relevant notes in the description and comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6488
ctrl+b: Move cursor backward (left)ctrl+f: Move cursor forward (right) - instead, it currently deletes the next wordctrl+p: Move cursor to the previous linectrl+n: Move cursor to the next linectrl+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.