Skip to content

Commit

Permalink
Do not request keyboard on controller update
Browse files Browse the repository at this point in the history
Fixes #301
  • Loading branch information
Amir-P committed Jul 5, 2024
1 parent 1b4bbbf commit 63363e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
2 changes: 0 additions & 2 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,6 @@ class RawEditorState extends EditorState
}

void _didChangeTextEditingValue() {
requestKeyboard();

_showCaretOnScreen();
updateRemoteValueIfNeeded();
_cursorController.startOrStopCursorTimerIfNeeded(
Expand Down
11 changes: 10 additions & 1 deletion packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
47 changes: 21 additions & 26 deletions packages/fleather/test/widgets/history_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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
Expand All @@ -131,44 +131,39 @@ void main() {

testWidgets('update widget', (tester) async {
Future<void> showKeyboard() async {
return TestAsyncUtils.guard<void>(() async {
final editor = tester.state<RawEditorState>(find.byType(RawEditor));
editor.requestKeyboard();
await tester.pumpAndSettle();
});
final editor = tester.state<RawEditorState>(find.byType(RawEditor));
editor.requestKeyboard();
await tester.pumpAndSettle();
}

Future<void> enterText(TextEditingValue text) async {
return TestAsyncUtils.guard<void>(() 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',
Expand Down

0 comments on commit 63363e1

Please sign in to comment.