Add "Select All" functionality on Ctrl+A to TextEditor#2321
Merged
hecrj merged 1 commit intoiced-rs:masterfrom Jul 7, 2024
Merged
Add "Select All" functionality on Ctrl+A to TextEditor#2321hecrj merged 1 commit intoiced-rs:masterfrom
hecrj merged 1 commit intoiced-rs:masterfrom
Conversation
|
stupid question: what is missing here? I would really like to have that 🥺 |
Contributor
Author
|
I've been using this PR's branch in production1 for several months now and it's been fine, so I don't think there is much missing for this particular feature :) Just waiting for a review. Footnotes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withSelectWordandSelectLine, 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.