Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Jul 16, 2018

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.

@Hixie
Copy link
Contributor

Hixie commented Jul 18, 2018

This will need a test.

@Hixie
Copy link
Contributor

Hixie commented Jul 18, 2018

Please when writing a test for this make the test comprehensive (check every combination of every possible TextPosition for each of aaa, \naaa, a\naa, aa\na, aaa\n as well as other esoteric combinations you can come up with like a\n\na or \n\n\n).

@jonahwilliams
Copy link
Contributor Author

@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);
});
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

@jonahwilliams
Copy link
Contributor Author

@Hixie Added more test cases ... I think if we want more we should just fuzz it

@jonahwilliams
Copy link
Contributor Author

@Hixie friendly ping

@Hixie
Copy link
Contributor

Hixie commented Jul 24, 2018

LGTM

@jonahwilliams jonahwilliams merged commit fba4fdb into flutter:master Jul 24, 2018
@jonahwilliams jonahwilliams deleted the text_affinity_bug branch July 24, 2018 21:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editing multiline text sometimes places cursor on the wrong line

3 participants