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

Merged
merged 1 commit into from
Jul 7, 2024

Conversation

PgBiel
Copy link
Contributor

@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.

@m0ppers
Copy link

m0ppers commented Jun 24, 2024

stupid question: what is missing here? I would really like to have that 🥺

@PgBiel
Copy link
Contributor Author

PgBiel commented Jun 24, 2024

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

  1. https://github.com/PgBiel/typst-ansi-gui

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks 🥳

@hecrj hecrj enabled auto-merge July 7, 2024 23:16
@hecrj hecrj added this to the 0.13 milestone Jul 7, 2024
@hecrj hecrj added feature New feature or request text widget addition labels Jul 7, 2024
@hecrj hecrj merged commit acf6daf into iced-rs:master Jul 7, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl+A in TextEditor should select all text
3 participants