Skip to content

Commit

Permalink
Enable auto correct (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson authored Jun 4, 2024
1 parent 34b56e7 commit 178d2bb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -451,6 +457,7 @@ class _FleatherEditorState extends State<FleatherEditor>
scrollable: widget.scrollable,
padding: widget.padding,
autofocus: widget.autofocus,
autocorrect: widget.autocorrect,
showCursor: widget.showCursor,
readOnly: widget.readOnly,
enableInteractiveSelection: widget.enableInteractiveSelection,
Expand Down Expand Up @@ -551,6 +558,7 @@ class RawEditor extends StatefulWidget {
this.autofocus = false,
bool? showCursor,
this.readOnly = false,
this.autocorrect = true,
this.enableInteractiveSelection = true,
this.minHeight,
this.maxHeight,
Expand Down Expand Up @@ -602,6 +610,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<String?>? onLaunchUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
inputType: TextInputType.multiline,
readOnly: widget.readOnly,
obscureText: false,
autocorrect: false,
autocorrect: widget.autocorrect,
enableDeltaModel: true,
inputAction: TextInputAction.newline,
keyboardAppearance: widget.keyboardAppearance,
Expand Down
7 changes: 7 additions & 0 deletions packages/fleather/lib/src/widgets/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -245,6 +251,7 @@ class _FleatherFieldState extends State<FleatherField> {
autofocus: widget.autofocus,
showCursor: widget.showCursor,
readOnly: widget.readOnly,
autocorrect: widget.autocorrect,
enableInteractiveSelection: widget.enableInteractiveSelection,
minHeight: widget.minHeight,
maxHeight: widget.maxHeight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions packages/fleather/test/widgets/editor_input_client_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,29 @@ void main() {
}
});
});

group('send editor options to TextInputConnection', () {
testWidgets('send autocorrect option', (tester) async {
Map<String, dynamic>? 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,
);
});
});
}

0 comments on commit 178d2bb

Please sign in to comment.