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

Add "Select All" functionality on Ctrl+A to TextEditor #2321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PgBiel
Copy link

@PgBiel PgBiel commented Mar 10, 2024

Closes #2153.

In principle, a very simple implementation: I created Action::SelectAll, which is reacted to by moving the selection to the start and the cursor to the end of the buffer. I've tested with a local project in my NixOS Linux box and it seemed to work fine, I could also use this to copy the whole buffer etc.

I also added some code to only perform this selection if the buffer isn't empty, which seems consistent with most text editors I've tried (and also with TextInput). Some platforms (such as some browsers and messaging apps) do, however, allow Ctrl+A to select all even on an empty buffer, so, if this is desired, let me know - but the behavior I chose seems to be consistent with SelectWord and SelectLine, for example.

Since modifiers.command() is used, this should cleanly translate to Cmd+A on MacOS, but I haven't tested explicitly.

Finally, there was a performance concern over at #2153 (comment). I'm not sure how up-to-date that comment is (it's possible TextEditor's code has changed significantly since then), but, in principle, this implementation seems to perform fine, even with hundreds of thousands of lines of text (pasting those lines took much longer (upwards of 15s) than selecting all of them, which took less than a second).

NOTE: In my empty buffer check, I use Option::is_some_and, which is a Rust 1.70.0+ feature. Let me know if I should replace it if this doesn't meet MSRV criteria. And feel free to drop any further suggestions!

NOTE: I didn't make any changes to TextInput; it appears to already have support for Ctrl+A functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+A in TextEditor should select all text
1 participant