Add delete-to-end to Input

And in doing so bind it to Ctrl+K (macOS/Emacs/readline-common). Right now
I'm not aware of a common combo for this on Windows, but we can add a
binding for this if one becomes apparent.

See #1310.
This commit is contained in:
Dave Pearson
2023-01-26 13:59:07 +00:00
parent 5d67c76a70
commit 487b2e2493

View File

@@ -87,6 +87,7 @@ class Input(Widget, can_focus=True):
Binding("end,ctrl+e", "end", "end", show=False),
Binding("ctrl+d,delete", "delete_right", "delete right", show=False),
Binding("enter", "submit", "submit", show=False),
Binding("ctrl+k", "delete_to_end", "delete to end", show=False),
]
COMPONENT_CLASSES = {"input--cursor", "input--placeholder"}
@@ -327,6 +328,10 @@ class Input(Widget, can_focus=True):
self.value = f"{before}{after}"
self.cursor_position = delete_position
def action_delete_to_end(self) -> None:
"""Delete from the cursor location to the end of input."""
self.value = self.value[: self.cursor_position]
async def action_submit(self) -> None:
await self.emit(self.Submitted(self, self.value))