From 997a14557ecce47c313f04385476a2210d7ac16f Mon Sep 17 00:00:00 2001 From: Simon Bengtsson Date: Wed, 29 May 2024 13:36:21 +0200 Subject: [PATCH 1/4] Enable auto correct --- .../fleather/lib/src/widgets/editor_input_client_mixin.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart index 642400e2..8fbfc521 100644 --- a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart +++ b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart @@ -57,7 +57,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState inputType: TextInputType.multiline, readOnly: widget.readOnly, obscureText: false, - autocorrect: false, + autocorrect: true, enableDeltaModel: true, inputAction: TextInputAction.newline, keyboardAppearance: widget.keyboardAppearance, From 966a9d63d8a2bdb70a1b51b3962ed17b3fc729fc Mon Sep 17 00:00:00 2001 From: Simon Bengtsson Date: Wed, 29 May 2024 15:32:52 +0200 Subject: [PATCH 2/4] Add autocorrect option --- packages/fleather/lib/src/widgets/editor.dart | 12 ++++++++++++ .../lib/src/widgets/editor_input_client_mixin.dart | 2 +- packages/fleather/lib/src/widgets/field.dart | 7 +++++++ .../editor_input_client_mixin_deltas_test.dart | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index 0f9f9d27..46075092 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -155,6 +155,11 @@ class FleatherEditor extends StatefulWidget { /// Defaults to `false`. Must not be `null`. final bool readOnly; + /// Whether to enable autocorrection. + /// + /// Defaults to `true`. + final bool autocorrect; + /// Whether to enable user interface affordances for changing the /// text selection. /// @@ -283,6 +288,7 @@ class FleatherEditor extends StatefulWidget { this.autofocus = false, this.showCursor = true, this.readOnly = false, + this.autocorrect = true, this.enableInteractiveSelection = true, this.minHeight, this.maxHeight, @@ -551,6 +557,7 @@ class RawEditor extends StatefulWidget { this.autofocus = false, bool? showCursor, this.readOnly = false, + this.autocorrect = true, this.enableInteractiveSelection = true, this.minHeight, this.maxHeight, @@ -602,6 +609,11 @@ class RawEditor extends StatefulWidget { /// Defaults to false. Must not be null. final bool readOnly; + /// Whether to enable autocorrection. + /// + /// Defaults to `true`. + final bool autocorrect; + /// Callback which is triggered when the user wants to open a URL from /// a link in the document. final ValueChanged? onLaunchUrl; diff --git a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart index 8fbfc521..17d38454 100644 --- a/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart +++ b/packages/fleather/lib/src/widgets/editor_input_client_mixin.dart @@ -57,7 +57,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState inputType: TextInputType.multiline, readOnly: widget.readOnly, obscureText: false, - autocorrect: true, + autocorrect: widget.autocorrect, enableDeltaModel: true, inputAction: TextInputAction.newline, keyboardAppearance: widget.keyboardAppearance, diff --git a/packages/fleather/lib/src/widgets/field.dart b/packages/fleather/lib/src/widgets/field.dart index c38a37a4..96debfe8 100644 --- a/packages/fleather/lib/src/widgets/field.dart +++ b/packages/fleather/lib/src/widgets/field.dart @@ -65,6 +65,11 @@ class FleatherField extends StatefulWidget { /// Defaults to `false`. Must not be `null`. final bool readOnly; + /// Whether to enable autocorrection. + /// + /// Defaults to `true`. + final bool autocorrect; + /// Whether to enable user interface affordances for changing the /// text selection. /// @@ -175,6 +180,7 @@ class FleatherField extends StatefulWidget { this.autofocus = false, this.showCursor = true, this.readOnly = false, + this.autocorrect = true, this.enableInteractiveSelection = true, this.minHeight, this.maxHeight, @@ -245,6 +251,7 @@ class _FleatherFieldState extends State { autofocus: widget.autofocus, showCursor: widget.showCursor, readOnly: widget.readOnly, + autocorrect: widget.autocorrect, enableInteractiveSelection: widget.enableInteractiveSelection, minHeight: widget.minHeight, maxHeight: widget.maxHeight, diff --git a/packages/fleather/test/widgets/editor_input_client_mixin_deltas_test.dart b/packages/fleather/test/widgets/editor_input_client_mixin_deltas_test.dart index 35ade2cf..80ec5af7 100644 --- a/packages/fleather/test/widgets/editor_input_client_mixin_deltas_test.dart +++ b/packages/fleather/test/widgets/editor_input_client_mixin_deltas_test.dart @@ -127,6 +127,7 @@ void main() { style: const TextStyle(), spacing: const VerticalSpacing()))); when(() => rawEditor.controller).thenReturn(controller); when(() => rawEditor.readOnly).thenReturn(false); + when(() => rawEditor.autocorrect).thenReturn(true); when(() => rawEditor.keyboardAppearance).thenReturn(Brightness.light); when(() => rawEditor.textCapitalization) .thenReturn(TextCapitalization.none); From 5d81904cba9e5caafb14c29014359b80677f87af Mon Sep 17 00:00:00 2001 From: Simon Bengtsson Date: Thu, 30 May 2024 09:34:43 +0200 Subject: [PATCH 3/4] Pass autocorrect flag --- packages/fleather/lib/src/widgets/editor.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index 46075092..3b2d36be 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -457,6 +457,7 @@ class _FleatherEditorState extends State scrollable: widget.scrollable, padding: widget.padding, autofocus: widget.autofocus, + autocorrect: widget.autocorrect, showCursor: widget.showCursor, readOnly: widget.readOnly, enableInteractiveSelection: widget.enableInteractiveSelection, From 7c36d13ad4e073943c305571d3d1a6a631efe452 Mon Sep 17 00:00:00 2001 From: Simon Bengtsson Date: Thu, 30 May 2024 12:58:46 +0200 Subject: [PATCH 4/4] Add test to ensure autocorrect flag is sent to TextInputConnection --- .../editor_input_client_mixin_test.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/fleather/test/widgets/editor_input_client_mixin_test.dart b/packages/fleather/test/widgets/editor_input_client_mixin_test.dart index f3e1234f..b07e94cb 100644 --- a/packages/fleather/test/widgets/editor_input_client_mixin_test.dart +++ b/packages/fleather/test/widgets/editor_input_client_mixin_test.dart @@ -298,4 +298,29 @@ void main() { } }); }); + + group('send editor options to TextInputConnection', () { + testWidgets('send autocorrect option', (tester) async { + Map? textInputClientProperties; + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.textInput, (MethodCall methodCall) async { + if (methodCall.method == 'TextInput.setClient') { + textInputClientProperties = methodCall.arguments[1]; + } + return null; + }); + + final editor = + EditorSandBox(tester: tester, document: ParchmentDocument()); + await editor.pump(); + await editor.tap(); + tester.binding.scheduleWarmUpFrame(); + await tester.pumpAndSettle(); + + expect( + textInputClientProperties?['autocorrect'], + true, + ); + }); + }); }