Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextArea CTRL-k behavior request #4277

Closed
BillScherer opened this issue Mar 11, 2024 · 7 comments · Fixed by #4284
Closed

TextArea CTRL-k behavior request #4277

BillScherer opened this issue Mar 11, 2024 · 7 comments · Fixed by #4284
Assignees
Labels
enhancement New feature or request Task

Comments

@BillScherer
Copy link

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!

@Textualize Textualize deleted a comment from github-actions bot Mar 11, 2024
@davep
Copy link
Contributor

davep commented Mar 11, 2024

While I agree this would make sense, meanwhile, you could possibly go with something like this in your app:

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()

@BillScherer
Copy link
Author

Thanks! I'll give that a try.

@BillScherer
Copy link
Author

That works perfectly. Thanks again!

@davep davep added enhancement New feature or request Task labels Mar 11, 2024
@willmcgugan
Copy link
Collaborator

This feels like it should be the default behaviour.

@BillScherer
Copy link
Author

This is how it works in Emacs

@davep
Copy link
Contributor

davep commented Mar 11, 2024

(1+ team-emacs)

@davep davep self-assigned this Mar 12, 2024
davep added a commit to davep/textual that referenced this issue Mar 12, 2024
Following the expected behaviour for ctrl+k from Emacs (and so by extension
a text area on macOS -- see notes.app, or textedit.app, for example), this
adds an alternative action to TextArea that will delete to end of line or,
if the line is empty, will delete the line.

Also, to further enhance compatibility with expected ctrl+k behaviour, if
the cursor is on the end of the line and ctrl+k is pressed a delete-right is
performed.

Fixes Textualize#4277.
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants