Add delete-to-start to Input

And in doing so bind it to Ctrl+U (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 14:11:46 +00:00
parent 487b2e2493
commit 53c168c24c

View File

@@ -88,6 +88,7 @@ class Input(Widget, can_focus=True):
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),
Binding("ctrl+u", "delete_to_start", "delete to start", show=False),
]
COMPONENT_CLASSES = {"input--cursor", "input--placeholder"}
@@ -332,6 +333,12 @@ class Input(Widget, can_focus=True):
"""Delete from the cursor location to the end of input."""
self.value = self.value[: self.cursor_position]
def action_delete_to_start(self) -> None:
"""Delete from the cursor location to the start of input."""
if self.cursor_position > 0:
self.value = self.value[self.cursor_position :]
self.cursor_position = 0
async def action_submit(self) -> None:
await self.emit(self.Submitted(self, self.value))