Clear _scribbleCacheKey when connection closes (#122145)
Clear _scribbleCacheKey when connection closes
This commit is contained in:
@@ -3165,6 +3165,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
_textInputConnection!.close();
|
||||
_textInputConnection = null;
|
||||
_lastKnownRemoteTextEditingValue = null;
|
||||
_scribbleCacheKey = null;
|
||||
removeTextPlaceholder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -852,6 +852,87 @@ void main() {
|
||||
expect(focusNode.hasFocus, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('selection rects re-sent when refocused', (WidgetTester tester) async {
|
||||
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
|
||||
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||
if (methodCall.method == 'TextInput.setSelectionRects') {
|
||||
final List<dynamic> args = methodCall.arguments as List<dynamic>;
|
||||
final List<SelectionRect> selectionRects = <SelectionRect>[];
|
||||
for (final dynamic rect in args) {
|
||||
selectionRects.add(SelectionRect(
|
||||
position: (rect as List<dynamic>)[4] as int,
|
||||
bounds: Rect.fromLTWH(rect[0] as double, rect[1] as double, rect[2] as double, rect[3] as double),
|
||||
));
|
||||
}
|
||||
log.add(selectionRects);
|
||||
}
|
||||
});
|
||||
|
||||
final TextEditingController controller = TextEditingController();
|
||||
final ScrollController scrollController = ScrollController();
|
||||
controller.text = 'Text1';
|
||||
|
||||
Future<void> pumpEditableText({ double? width, double? height, TextAlign textAlign = TextAlign.start }) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: height,
|
||||
child: EditableText(
|
||||
controller: controller,
|
||||
textAlign: textAlign,
|
||||
scrollController: scrollController,
|
||||
maxLines: null,
|
||||
focusNode: focusNode,
|
||||
cursorWidth: 0,
|
||||
style: Typography.material2018().black.titleMedium!,
|
||||
cursorColor: Colors.blue,
|
||||
backgroundCursorColor: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const List<SelectionRect> expectedRects = <SelectionRect>[
|
||||
SelectionRect(position: 0, bounds: Rect.fromLTRB(0.0, 0.0, 14.0, 14.0)),
|
||||
SelectionRect(position: 1, bounds: Rect.fromLTRB(14.0, 0.0, 28.0, 14.0)),
|
||||
SelectionRect(position: 2, bounds: Rect.fromLTRB(28.0, 0.0, 42.0, 14.0)),
|
||||
SelectionRect(position: 3, bounds: Rect.fromLTRB(42.0, 0.0, 56.0, 14.0)),
|
||||
SelectionRect(position: 4, bounds: Rect.fromLTRB(56.0, 0.0, 70.0, 14.0))
|
||||
];
|
||||
|
||||
await pumpEditableText();
|
||||
expect(log, isEmpty);
|
||||
|
||||
await tester.showKeyboard(find.byType(EditableText));
|
||||
// First update.
|
||||
expect(log.single, expectedRects);
|
||||
log.clear();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(log, isEmpty);
|
||||
|
||||
focusNode.unfocus();
|
||||
await tester.pumpAndSettle();
|
||||
expect(log, isEmpty);
|
||||
|
||||
focusNode.requestFocus();
|
||||
//await tester.showKeyboard(find.byType(EditableText));
|
||||
await tester.pumpAndSettle();
|
||||
// Should re-receive the same rects.
|
||||
expect(log.single, expectedRects);
|
||||
log.clear();
|
||||
|
||||
// On web, we should rely on the browser's implementation of Scribble, so we will not send selection rects.
|
||||
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS })); // [intended]
|
||||
|
||||
testWidgets('EditableText does not derive selection color from DefaultSelectionStyle', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/103341.
|
||||
const TextEditingValue value = TextEditingValue(
|
||||
|
||||
Reference in New Issue
Block a user