From 63363e192039c85c550758640794d6ee35507062 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Fri, 5 Jul 2024 23:12:52 +0330 Subject: [PATCH] Do not request keyboard on controller update Fixes #301 --- packages/fleather/lib/src/widgets/editor.dart | 2 - .../fleather/test/widgets/editor_test.dart | 11 ++++- .../fleather/test/widgets/history_test.dart | 47 +++++++++---------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index cb55ec73..c02082f1 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -1454,8 +1454,6 @@ class RawEditorState extends EditorState } void _didChangeTextEditingValue() { - requestKeyboard(); - _showCaretOnScreen(); updateRemoteValueIfNeeded(); _cursorController.startOrStopCursorTimerIfNeeded( diff --git a/packages/fleather/test/widgets/editor_test.dart b/packages/fleather/test/widgets/editor_test.dart index 4f7414e2..aa911a8b 100644 --- a/packages/fleather/test/widgets/editor_test.dart +++ b/packages/fleather/test/widgets/editor_test.dart @@ -166,6 +166,15 @@ void main() { expect(text.children!.first.style!.color, Colors.red); }); + testWidgets('changes to controller does not request keyboard', + (tester) async { + final editor = EditorSandBox(tester: tester); + await editor.pump(); + await editor.updateSelection(base: 0, extent: 3); + await tester.pump(); + expect(editor.focusNode.hasFocus, false); + }); + testWidgets('collapses selection when unfocused', (tester) async { final editor = EditorSandBox(tester: tester, autofocus: true); await editor.pumpAndTap(); @@ -600,7 +609,7 @@ void main() { {'insert': 'Test test\n'} ]); final editor = EditorSandBox(tester: tester, document: document); - await editor.pump(); + await editor.pumpAndTap(); await editor.updateSelection(base: 1, extent: 2); await tester.sendKeyDownEvent(LogicalKeyboardKey.shift); final gesture = await tester.startGesture( diff --git a/packages/fleather/test/widgets/history_test.dart b/packages/fleather/test/widgets/history_test.dart index 5ac949a1..7d2ef755 100644 --- a/packages/fleather/test/widgets/history_test.dart +++ b/packages/fleather/test/widgets/history_test.dart @@ -65,7 +65,7 @@ void main() { ..retain(initialLength - 5) ..delete(5) ..insert('mmmmm,', {'i': true})); - await editor.pump(); + await editor.pumpAndTap(); final inputClient = getInputClient(); inputClient.openConnectionIfNeeded(); inputClient.updateEditingValueWithDeltas([ @@ -106,7 +106,7 @@ void main() { ..retain(initialLength - 5) ..delete(5) ..insert('mmmmm')); - await editor.pump(); + await editor.pumpAndTap(); editor.controller .formatText(initialLength - 5, 5, ParchmentAttribute.italic.unset); // Throttle time of 500ms in history @@ -131,44 +131,39 @@ void main() { testWidgets('update widget', (tester) async { Future showKeyboard() async { - return TestAsyncUtils.guard(() async { - final editor = tester.state(find.byType(RawEditor)); - editor.requestKeyboard(); - await tester.pumpAndSettle(); - }); + final editor = tester.state(find.byType(RawEditor)); + editor.requestKeyboard(); + await tester.pumpAndSettle(); } Future enterText(TextEditingValue text) async { - return TestAsyncUtils.guard(() async { - await showKeyboard(); - final inputClient = getInputClient(); - inputClient.updateEditingValueWithDeltas([ - TextEditingDeltaInsertion( - oldText: inputClient.textEditingValue.text, - textInserted: text.text, - insertionOffset: 0, - selection: text.selection, - composing: text.composing, - ) - ]); - tester.binding.testTextInput.updateEditingValue(text); - await tester.idle(); - await tester.pumpAndSettle(); - }); + await showKeyboard(); + final inputClient = getInputClient(); + inputClient.updateEditingValueWithDeltas([ + TextEditingDeltaInsertion( + oldText: inputClient.textEditingValue.text, + textInserted: text.text, + insertionOffset: 0, + selection: text.selection, + composing: text.composing, + ) + ]); + tester.binding.testTextInput.updateEditingValue(text); + await tester.idle(); + await tester.pumpAndSettle(); } final documentDelta = Delta()..insert('Something in the way mmmmm\n'); await tester.pumpWidget( MaterialApp( - home: TestUpdateWidget( - focusNodeAfterChange: FocusNode(), - ), + home: TestUpdateWidget(focusNodeAfterChange: FocusNode()), ), ); await tester.pumpAndSettle(); // update widget await tester.tap(find.byType(TextButton)); + await tester.pump(); await enterText(const TextEditingValue( text: 'Something in the way mmmmm',