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

Wrap word-wise selection when the word is actually wrapped #16441

Merged
merged 4 commits into from Dec 15, 2023

Conversation

js324
Copy link
Contributor

@js324 js324 commented Dec 7, 2023

Summary of the Pull Request

Added wrapping to highlighted selection when selecting a word, added tests for it

References and Relevant Issues

#4009

Detailed Description of the Pull Request / Additional comments

  • Modified GetWordStart and GetWordEnd and their helpers to no longer be bounded by the right and left viewport ranges
  • Kept same functionality (does not wrap) when selecting wrapped whitespace
  • Added tests to TextBufferTests.cpp to include cases of wrapping text

Just a thought, we currently select the "Line" on triple-click, but would it make more sense to include the wrapping functionality to this as well?

Validation Steps Performed

  • Ran locally and verified selection works properly
  • Tests passed locally

PR Checklist

Sorry about closing the last PR, tried cleaning up the commits when I was merging and accidentally closed it 🤦‍♂️

Revert "add wrapping selection and tests"

This reverts commit 9db88af.

add wrapping selection and tests

Revert "add wrapping selection and tests"

This reverts commit 9db88af.

add wrapping selection and tests

clean up and fixes

minor clean up

fix tests

fix spelling

add const

code formatting

spelling changes

code format

clean up and fixes

minor clean up

fix tests

code formatting
@js324 js324 changed the title Add wrapping selection when word is wrapped #16241 Add wrapping selection when word is wrapped Dec 7, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Task It's a feature request, but it doesn't really need a major design. Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. labels Dec 7, 2023
@DHowett
Copy link
Member

DHowett commented Dec 15, 2023

Thanks for bringing this PR back! I'm adding it to my docket for tomorrow.

@DHowett
Copy link
Member

DHowett commented Dec 15, 2023

(As you can probably guess, we start running out of staffing near the holidays! 😆)

@lhecker
Copy link
Member

lhecker commented Dec 15, 2023

Just a thought, we currently select the "Line" on triple-click, but would it make more sense to include the wrapping functionality to this as well?

Yeah I'd say so. If you triple click to select an entire line of text it should select as many rows as necessary to select one proper line with explicit line break (aka: row.WasWrapForced() == false).

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

I still feel somewhat squirmish about iterating by coordinates instead of iterating over the underlying text, but I also don't really see any flaws with this and I do think it's a genuine improvement over the old code (because it's not buggy). Thank you for tackling this issue!

To be entirely frank however, I think this code deserves to be rewritten from scratch at some point to use a simpler algorithm. For instance, we now have UTextFromTextBuffer which returns an ICU UText. We can then use ubrk_open(UBRK_WORD) to get proper Unicode word-wise navigation for languages that don't use spaces (Asian languages; in the future at some point). We can also implement delimiters more easily, accurately and in a way WAY more performant manner. uset_openPattern allows is to construct an efficient LUT from a string like "\\+!:=/.<>;|&". Then, you can just call UTEXT_NEXT32 and UTEXT_PREVIOUS32 to iterate through the backing buffer and ask the USet whether it's a delimiter char.

All that however requires a bigger rewrite...

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I see a bunch of the work is the mechanical change away from using a row cell iterator (which doesn't wrap) to manually walking the coordinates (which does). That'll work for me!

/cc @carlos-zamora as an advisory since he owns selection and accessibility, but I'm gonna merge this in for Canary anyway!

@DHowett DHowett changed the title Add wrapping selection when word is wrapped Wrap word-wise selection when the word is actually wrapped Dec 15, 2023
@DHowett
Copy link
Member

DHowett commented Dec 15, 2023

And for:

Just a thought, we currently select the "Line" on triple-click, but
would it make more sense to include the wrapping functionality to this
as well?

If you want to send in a followup PR for this, we'd love to review it! 😄

@DHowett DHowett merged commit 63c3573 into microsoft:main Dec 15, 2023
15 checks passed
@DHowett DHowett added this to To Cherry Pick in 1.19 Servicing Pipeline via automation Jan 30, 2024
@DHowett DHowett moved this from To Cherry Pick to To Consider in 1.19 Servicing Pipeline Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
Development

Successfully merging this pull request may close these issues.

Make double-click at the edge select across the edge
3 participants