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