mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
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:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user