-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix off by one error in TextPainter. #19429
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
Fix off by one error in TextPainter. #19429
Conversation
|
This will need a test. |
|
Please when writing a test for this make the test comprehensive (check every combination of every possible TextPosition for each of |
|
@Hixie I've added testing for the caret position across some different text strings |
| caretOffset = painter.getOffsetForCaret(new ui.TextPosition(offset: text.length, affinity: TextAffinity.upstream), ui.Rect.zero); | ||
| expect(caretOffset.dx, painter.width); | ||
| expect(caretOffset.dy, 0.0); | ||
| }); |
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.
we should check cases with leading newlines too
also for every case we should check both kinds of affinities
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.
also we should check positions other than the end of the string. Ideally check every interesting position for each of these strings.
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've added cases where I move up and down a text field with leading/trailing newlines with different affinities. Anything else I may have missed herE?
|
@Hixie Added more test cases ... I think if we want more we should just fuzz it |
|
@Hixie friendly ping |
Fixes #15572.
Not sure if this is the exact right solution, but it is close to the problem
Given a string such as
abc, _getOffsetFromDownstream will return null (out of bounds) and the cursor will correctly be placed at the end of the first line.Given a string such as
abc\n_getOffsetFromDownstream will return null and the cursor will incorrectly be placed at the end of the first line.When deleting text, the affinity changes to upstream and the above issues do not apply.