Repository: Textualize/textual

Issue:
TextArea CTRL-k behavior request
Requesting CTRL-k (C-k) behavior be modified as follows.

C-k currently does not kill new lines, and on a line with printable content, this is correct. On a line with only a newline, C-k *should* kill the new line. This will allow the TextArea user to kill multiple lines simply with repeated application of C-k. The current behavior of never killing a newline requires more effort that in it should. Thanks!


Discussion:
While I agree this would make sense, meanwhile, you could possibly go with something like this in your app:

```python
from textual.app import App, ComposeResult
from textual.widgets import TextArea

class TextAreaEx(TextArea):
    """Extended TextArea."""

    def action_delete_to_end_of_line(self) -> None:
        if self.selection.end != self.get_cursor_line_end_location():
            super().action_delete_to_end_of_line()
        else:
            self.action_delete_line()

class CtrlKApp(App[None]):

    def compose(self) -> ComposeResult:
        yield TextAreaEx()

if __name__ == "__main__":
    CtrlKApp().run()
```

Thanks! I'll give that a try.
That works perfectly. Thanks again!
This feels like it should be the default behaviour.
This is how it works in Emacs
`(1+ team-emacs)`

Resolving patch:
diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py
--- a/src/textual/widgets/_text_area.py
+++ b/src/textual/widgets/_text_area.py
@@ -219,7 +219,12 @@ class TextArea(ScrollView):
         Binding(
             "ctrl+u", "delete_to_start_of_line", "delete to line start", show=False
         ),
-        Binding("ctrl+k", "delete_to_end_of_line", "delete to line end", show=False),
+        Binding(
+            "ctrl+k",
+            "delete_to_end_of_line_or_delete_line",
+            "delete to line end",
+            show=False,
+        ),
         Binding("ctrl+z", "undo", "Undo", show=False),
         Binding("ctrl+y", "redo", "Redo", show=False),
     ]
@@ -2112,6 +2117,26 @@ def action_delete_to_end_of_line(self) -> None:
         to_location = self.get_cursor_line_end_location()
         self._delete_via_keyboard(from_location, to_location)
 
+    async def action_delete_to_end_of_line_or_delete_line(self) -> None:
+        """Deletes from the cursor location to the end of the line, or deletes the line.
+
+        The line will be deleted if the line is empty.
+        """
+        # Assume we're just going to delete to the end of the line.
+        action = "delete_to_end_of_line"
+        if self.get_cursor_line_start_location() == self.get_cursor_line_end_location():
+            # The line is empty, so we'll simply remove the line itself.
+            action = "delete_line"
+        elif (
+            self.selection.start
+            == self.selection.end
+            == self.get_cursor_line_end_location()
+        ):
+            # We're at the end of the line, so the kill delete operation
+            # should join the next line to this.
+            action = "delete_right"
+        await self.run_action(action)
+
     def action_delete_word_left(self) -> None:
         """Deletes the word to the left of the cursor and updates the cursor location."""
         if self.cursor_at_start_of_text:


Test patch: