From 87139861e63b71b7c60bdc29f9f6b0a5976e692d Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Fri, 22 Sep 2023 08:00:58 +0200 Subject: [PATCH] [iOS] Disable spelling corrections when auto correction is disabled (flutter/engine#46144) ## Description This iOS PR disables spellchecking when auto correction is disabled. ## Related Issue Fixes https://github.com/flutter/flutter/issues/134881. ## Tests Adds 1 test. --- .../framework/Source/FlutterTextInputPlugin.mm | 8 +++++--- .../Source/FlutterTextInputPluginTest.mm | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index c47a5566e5..f02ab85da7 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -878,9 +878,11 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, self.keyboardAppearance = UIKeyboardAppearanceDefault; } NSString* autocorrect = configuration[kAutocorrectionType]; - self.autocorrectionType = autocorrect && ![autocorrect boolValue] - ? UITextAutocorrectionTypeNo - : UITextAutocorrectionTypeDefault; + bool autocorrectIsDisabled = autocorrect && ![autocorrect boolValue]; + self.autocorrectionType = + autocorrectIsDisabled ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault; + self.spellCheckingType = + autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; self.autofillId = AutofillIdFromDictionary(configuration); if (autofill == nil) { self.textContentType = @""; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index 701621273c..f18357acf0 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -769,6 +769,23 @@ FLUTTER_ASSERT_ARC OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]); } +- (void)testDisablingAutocorrectDisablesSpellChecking { + FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; + + // Disable the interactive selection. + NSDictionary* config = self.mutableTemplateCopy; + [inputView configureWithDictionary:config]; + + XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeDefault); + XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeDefault); + + [config setValue:@(NO) forKey:@"autocorrect"]; + [inputView configureWithDictionary:config]; + + XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeNo); + XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo); +} + #pragma mark - TextEditingDelta tests - (void)testTextEditingDeltasAreGeneratedOnTextInput { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];