Same cursor offset within lines for all TextAffinities to prevent cursor shifting/moving. (#23485)

This commit is contained in:
Gary Qian 2018-10-26 10:21:25 -07:00 committed by GitHub
parent 340c158f32
commit 6827d0920b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -1 +1 @@
afef1dc571f94a41751917d3946defba782335f7
055a75c5a63bf2b2c5142b38b88829593908fd10

View File

@ -421,7 +421,7 @@ class TextPainter {
return null;
final TextBox box = boxes[0];
final double caretEnd = box.end;
final double dx = box.direction == TextDirection.rtl ? caretEnd : caretEnd - caretPrototype.width;
final double dx = box.direction == TextDirection.rtl ? caretEnd - caretPrototype.width : caretEnd;
return Offset(dx, box.top);
}

View File

@ -741,6 +741,11 @@ void main() {
final Offset firstPos = textOffsetToPosition(tester, testValue.indexOf('First'));
final Offset secondPos = textOffsetToPosition(tester, testValue.indexOf('Second'));
final Offset thirdPos = textOffsetToPosition(tester, testValue.indexOf('Third'));
final Offset middleStringPos = textOffsetToPosition(tester, testValue.indexOf('irst'));
expect(firstPos.dx, 0);
expect(secondPos.dx, 0);
expect(thirdPos.dx, 0);
expect(middleStringPos.dx, 34);
expect(firstPos.dx, secondPos.dx);
expect(firstPos.dx, thirdPos.dx);
expect(firstPos.dy, lessThan(secondPos.dy));
@ -823,6 +828,8 @@ void main() {
// Check that the last line of text is not displayed.
final Offset firstPos = textOffsetToPosition(tester, kMoreThanFourLines.indexOf('First'));
final Offset fourthPos = textOffsetToPosition(tester, kMoreThanFourLines.indexOf('Fourth'));
expect(firstPos.dx, 0);
expect(fourthPos.dx, 0);
expect(firstPos.dx, fourthPos.dx);
expect(firstPos.dy, lessThan(fourthPos.dy));
expect(inputBox.hitTest(HitTestResult(), position: inputBox.globalToLocal(firstPos)), isTrue);