Unverified Commit cd6279c1 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

fix _getPixelPerfectCursorOffset logic when infinite (#66845)

parent 9efdcf61
......@@ -1999,15 +1999,17 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
offset.applyContentDimensions(0.0, _maxScrollExtent);
}
/// Computes the offset to apply to the given [caretRect] so it perfectly
/// snaps to physical pixels.
Offset _getPixelPerfectCursorOffset(Rect caretRect) {
final Offset caretPosition = localToGlobal(caretRect.topLeft);
final double pixelMultiple = 1.0 / _devicePixelRatio;
final double pixelPerfectOffsetX = caretPosition.dx.isFinite
? (caretPosition.dx / pixelMultiple).round() * pixelMultiple - caretPosition.dx
: caretPosition.dx;
: 0;
final double pixelPerfectOffsetY = caretPosition.dy.isFinite
? (caretPosition.dy / pixelMultiple).round() * pixelMultiple - caretPosition.dy
: caretPosition.dy;
: 0;
return Offset(pixelPerfectOffsetX, pixelPerfectOffsetY);
}
......
......@@ -3427,17 +3427,22 @@ void main() {
});
testWidgets(
'does not throw when sending infinite Rect',
'zero matrix paint transform',
(WidgetTester tester) async {
controller.value = TextEditingValue(text: 'a' * 100, composing: const TextRange(start: 0, end: 10));
// Use a FittedBox with an zero-sized child to set the paint transform
// to the zero matrix.
await tester.pumpWidget(FittedBox(child: SizedBox.fromSize(size: Size.zero, child: builder())));
await tester.showKeyboard(find.byType(EditableText));
expect(tester.testTextInput.log, contains(matchesMethodCall('TextInput.setMarkedTextRect', args: <String, dynamic> {
'width': -1,
'height': -1,
'x': 0,
'y': 0,
})));
expect(tester.testTextInput.log, contains(matchesMethodCall(
'TextInput.setMarkedTextRect',
args: allOf(
containsPair('width', isNotNaN),
containsPair('height', isNotNaN),
containsPair('x', isNotNaN),
containsPair('y', isNotNaN),
),
)));
});
});
......@@ -4695,7 +4700,7 @@ void main() {
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
final Rect rect = state.renderEditable.getLocalRectForCaret(const TextPosition(offset: 0));
expect(rect.isFinite, false);
expect(rect.isFinite, true);
expect(tester.takeException(), isNull);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment