This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Paragraph.GetWordBoundary respects text affinity #36176
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextPosition's documentation saysso that seems to indicate that the same
TextPositioncan either be interpreted as anintwhich points to a code unit in a UTF16 string, or a place to draw the caret in the rendered string.This works but it should be stated in the documentation that
TextPositionhere is a caret location instead of an offset (but I feel it's easier to reason about word boundaries using code unit offsets instead of using caret locations). I think i'd prefer we useTextPositionexclusively for caret positions, and letgetWordBoundarytake anintinstead ofTextPositionto avoid ambiguity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it was initially an
intand was changed in https://github.com/flutter/engine/pull/13765/files. @gspencergoog is there a reason for usingTextPositionoverinthere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like some of the text in this thread should become code comments for future reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was three years ago, so it's hazy, but I think it had to do with being able to move line by line. Here's some additional context: #13727
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the previous pr it looks like it just part of moving TextRange and related class to ui to fix some line boundary issue, and the getWordBoundary just some how refactor to matches the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is really down to when we want to make the switch from caret position to code unit position. In my opinion it should be as late as possible in case the a later step may want to use the caret position and they have to do some other hack to restore it back. WDYT @LongCatIsLooong
I think we should always treat TextPosition as a caret position, and use int if it meant to be a code unit position. Otherwise, it will create convoluted code. I will update the document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#28008 made
getLineBoundaryTextAffinity aware. I'm ok with making them consistent and document that the parameter is based on the caret location instead of the character location. But still word boundaries generally don't require layout and the caller may just want to tokenize the text without even putting the text on screen. Talking about "caret position" could be confusing in this context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the input may come from a getPositionForOffset from a touch event, which is affinity aware. I will keep it as is and document it. Thanks for the input.