@@ -13011,6 +13011,58 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
1301113011 // On web, these keyboard shortcuts are handled by the browser.
1301213012 }, variant: TargetPlatformVariant.only(TargetPlatform.android), skip: kIsWeb); // [intended]
1301313013
13014+ // Regression test for https://github.com/flutter/flutter/issues/120194.
13015+ testWidgets('Cursor does not jump after undo', (WidgetTester tester) async {
13016+ // Initialize the controller with a non empty text.
13017+ final TextEditingController controller = TextEditingController(text: textA);
13018+ final FocusNode focusNode = FocusNode();
13019+ await tester.pumpWidget(boilerplate(controller, focusNode));
13020+
13021+ // Focus the field and wait for throttling delay to get the initial
13022+ // state saved in text editing history.
13023+ focusNode.requestFocus();
13024+ await tester.pump();
13025+ await waitForThrottling(tester);
13026+ expect(controller.value, textACollapsedAtEnd);
13027+
13028+ // Insert some text.
13029+ await tester.enterText(find.byType(EditableText), textAB);
13030+ expect(controller.value, textABCollapsedAtEnd);
13031+
13032+ // Undo the insertion without waiting for the throttling delay.
13033+ await sendUndo(tester);
13034+ expect(controller.value.selection.isValid, true);
13035+ expect(controller.value, textACollapsedAtEnd);
13036+
13037+ // On web, these keyboard shortcuts are handled by the browser.
13038+ }, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
13039+
13040+ testWidgets('Initial value is recorded when an undo is received just after getting the focus', (WidgetTester tester) async {
13041+ // Initialize the controller with a non empty text.
13042+ final TextEditingController controller = TextEditingController(text: textA);
13043+ final FocusNode focusNode = FocusNode();
13044+ await tester.pumpWidget(boilerplate(controller, focusNode));
13045+
13046+ // Focus the field and do not wait for throttling delay before calling undo.
13047+ focusNode.requestFocus();
13048+ await tester.pump();
13049+ await sendUndo(tester);
13050+ await waitForThrottling(tester);
13051+ expect(controller.value, textACollapsedAtEnd);
13052+
13053+ // Insert some text.
13054+ await tester.enterText(find.byType(EditableText), textAB);
13055+ expect(controller.value, textABCollapsedAtEnd);
13056+
13057+ // Undo the insertion.
13058+ await sendUndo(tester);
13059+
13060+ // Initial text should have been recorded and restored.
13061+ expect(controller.value, textACollapsedAtEnd);
13062+
13063+ // On web, these keyboard shortcuts are handled by the browser.
13064+ }, variant: TargetPlatformVariant.all(), skip: kIsWeb); // [intended]
13065+
1301413066 testWidgets('Can make changes in the middle of the history', (WidgetTester tester) async {
1301513067 final TextEditingController controller = TextEditingController();
1301613068 final FocusNode focusNode = FocusNode();
0 commit comments