Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

iOS UITextInput autocorrection prompt #13959

Merged
merged 26 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0b0000d
add new method for autocorrection
LongCatIsLooong Jun 21, 2019
4846f35
account for multistage input
LongCatIsLooong Jun 24, 2019
8a61354
add new method to FlutterTextInputDelegate
LongCatIsLooong Jun 25, 2019
6246afc
add cause
LongCatIsLooong Jun 26, 2019
a5f99ce
move TODO around
LongCatIsLooong Jun 26, 2019
ee9bd5b
fix format
LongCatIsLooong Jun 27, 2019
dd30a95
Merge branch 'master' into autocorrection
LongCatIsLooong Oct 23, 2019
24fceeb
update
LongCatIsLooong Oct 28, 2019
920f446
update
LongCatIsLooong Oct 28, 2019
6531251
add test
LongCatIsLooong Oct 28, 2019
e9801d9
Merge remote-tracking branch 'upstream/master' into autocorrection
LongCatIsLooong Oct 28, 2019
6ff5711
Merge remote-tracking branch 'upstream/master' into autocorrection
LongCatIsLooong Nov 1, 2019
7d12820
add tests
LongCatIsLooong Nov 20, 2019
2c194d6
using arc for xctest
LongCatIsLooong Nov 20, 2019
180ed36
revert changes
LongCatIsLooong Nov 20, 2019
2d20e8f
format
LongCatIsLooong Nov 20, 2019
56ead3c
comments
LongCatIsLooong Nov 20, 2019
bf486b6
Merge remote-tracking branch 'upstream/master' into autocorrection
LongCatIsLooong Nov 20, 2019
bb81680
update test name
LongCatIsLooong Nov 20, 2019
cf097be
remove newline
LongCatIsLooong Nov 21, 2019
2237603
formatting
LongCatIsLooong Nov 26, 2019
cc7eb04
update licenses
LongCatIsLooong Nov 26, 2019
792c37f
Update FlutterTextInputPluginTest.m
LongCatIsLooong Dec 5, 2019
e907174
license
LongCatIsLooong Dec 18, 2019
ea80b67
merge upstream/master
LongCatIsLooong Dec 18, 2019
636ebf8
Merge remote-tracking branch 'upstream/master' into autocorrection
LongCatIsLooong Apr 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginA
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUmbrellaImport.m
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,13 @@ - (void)performAction:(FlutterTextInputAction)action withClient:(int)client {
arguments:@[ @(client), actionString ]];
}

- (void)showAutocorrectionPromptRectForStart:(NSUInteger)start
end:(NSUInteger)end
withClient:(int)client {
[_textInputChannel.get() invokeMethod:@"TextInputClient.showAutocorrectionPromptRect"
arguments:@[ @(client), @(start), @(end) ]];
}

#pragma mark - Screenshot Delegate

- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) {
- (void)updateFloatingCursor:(FlutterFloatingCursorDragState)state
withClient:(int)client
withPosition:(NSDictionary*)point;

- (void)showAutocorrectionPromptRectForStart:(NSUInteger)start
end:(NSUInteger)end
withClient:(int)client;
@end

#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTDELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
@end

/** A range of text in the buffer of a Flutter text editing widget. */
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
FLUTTER_EXPORT
#endif
@interface FlutterTextRange : UITextRange <NSCopying>

@property(nonatomic, readonly) NSRange range;
Expand All @@ -44,4 +47,32 @@

@end

#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
FLUTTER_EXPORT
#endif
@interface FlutterTextInputView : UIView <UITextInput>

// UITextInput
@property(nonatomic, readonly) NSMutableString* text;
@property(nonatomic, readonly) NSMutableString* markedText;
@property(readwrite, copy) UITextRange* selectedTextRange;
@property(nonatomic, strong) UITextRange* markedTextRange;
@property(nonatomic, copy) NSDictionary* markedTextStyle;
@property(nonatomic, assign) id<UITextInputDelegate> inputDelegate;

// UITextInputTraits
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
@property(nonatomic) UITextSpellCheckingType spellCheckingType;
@property(nonatomic) BOOL enablesReturnKeyAutomatically;
@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
@property(nonatomic) UIKeyboardType keyboardType;
@property(nonatomic) UIReturnKeyType returnKeyType;
@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
@property(nonatomic) UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0));
@property(nonatomic) UITextSmartDashesType smartDashesType API_AVAILABLE(ios(11.0));

@property(nonatomic, assign) id<FlutterTextInputDelegate> textInputDelegate;

@end
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,6 @@ - (id)copyWithZone:(NSZone*)zone {

@end

@interface FlutterTextInputView : UIView <UITextInput>

// UITextInput
@property(nonatomic, readonly) NSMutableString* text;
@property(nonatomic, readonly) NSMutableString* markedText;
@property(readwrite, copy) UITextRange* selectedTextRange;
@property(nonatomic, strong) UITextRange* markedTextRange;
@property(nonatomic, copy) NSDictionary* markedTextStyle;
@property(nonatomic, assign) id<UITextInputDelegate> inputDelegate;

// UITextInputTraits
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
@property(nonatomic) UITextSpellCheckingType spellCheckingType;
@property(nonatomic) BOOL enablesReturnKeyAutomatically;
@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
@property(nonatomic) UIKeyboardType keyboardType;
@property(nonatomic) UIReturnKeyType returnKeyType;
@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
@property(nonatomic) UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0));
@property(nonatomic) UITextSmartDashesType smartDashesType API_AVAILABLE(ios(11.0));

@property(nonatomic, assign) id<FlutterTextInputDelegate> textInputDelegate;

@end

@implementation FlutterTextInputView {
int _textInputClient;
const char* _selectionAffinity;
Expand Down Expand Up @@ -554,6 +528,16 @@ - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
// physical keyboard.

- (CGRect)firstRectForRange:(UITextRange*)range {
// multi-stage text is handled somewhere else.
if (_markedTextRange != nil) {
return CGRectZero;
}

NSUInteger start = ((FlutterTextPosition*)range.start).index;
NSUInteger end = ((FlutterTextPosition*)range.end).index;
[_textInputDelegate showAutocorrectionPromptRectForStart:start
end:end
withClient:_textInputClient];
// TODO(cbracken) Implement.
return CGRectZero;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update the year to 2019.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2013 is the correct/approved year to use for all copyright dates in the engine. This has the effect of minimising our LICENSES text.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops I have messed this up all over the place 😊 Thanks for the correction! I'll move these back to 2013 when I see them.

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#include "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"

FLUTTER_ASSERT_ARC

@interface FlutterTextInputPluginTest : XCTestCase
@end

@implementation FlutterTextInputPluginTest

- (void)testAutocorrectionPromptRectAppears {
// Setup test.
id engine = OCMClassMock([FlutterEngine class]);

FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithFrame:CGRectZero];
inputView.textInputDelegate = engine;
[inputView firstRectForRange:[FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)]];

// Verify behavior.
OCMVerify([engine showAutocorrectionPromptRectForStart:0 end:1 withClient:0]);

// Clean up mocks
[engine stopMocking];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
0D6AB6EB22BB40E700EEE540 /* FlutterEngineTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0D6AB6E722BB40CF00EEE540 /* FlutterEngineTest.mm */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
0D6AB72C22BC339F00EEE540 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D6AB72522BC336100EEE540 /* libOCMock.a */; };
0D6AB73F22BD8F0200EEE540 /* FlutterEngineConfig.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 0D6AB73E22BD8F0200EEE540 /* FlutterEngineConfig.xcconfig */; };
3D8AF6182384C5420033B95F /* FlutterTextInputPluginTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D8AF6172384C5420033B95F /* FlutterTextInputPluginTest.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -94,6 +95,7 @@
0D6AB6E722BB40CF00EEE540 /* FlutterEngineTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterEngineTest.mm; sourceTree = "<group>"; };
0D6AB71722BC336100EEE540 /* OCMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OCMock.xcodeproj; path = ../../../../../third_party/ocmock/Source/OCMock.xcodeproj; sourceTree = "<group>"; };
0D6AB73E22BD8F0200EEE540 /* FlutterEngineConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = FlutterEngineConfig.xcconfig; sourceTree = "<group>"; };
3D8AF6172384C5420033B95F /* FlutterTextInputPluginTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlutterTextInputPluginTest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -176,6 +178,7 @@
children = (
0D52D3B622C566D50011DEBD /* FlutterBinaryMessengerRelayTest.mm */,
0D6AB6E722BB40CF00EEE540 /* FlutterEngineTest.mm */,
3D8AF6172384C5420033B95F /* FlutterTextInputPluginTest.m */,
0D17A5BF22D78FCD0057279F /* FlutterViewControllerTest.m */,
0D4C3FAF22DF9F5300A67C70 /* FlutterPluginAppLifeCycleDelegateTest.m */,
);
Expand Down Expand Up @@ -387,6 +390,7 @@
buildActionMask = 2147483647;
files = (
0D6AB6EB22BB40E700EEE540 /* FlutterEngineTest.mm in Sources */,
3D8AF6182384C5420033B95F /* FlutterTextInputPluginTest.m in Sources */,
0D17A5C022D78FCD0057279F /* FlutterViewControllerTest.m in Sources */,
0D1CE5D8233430F400E5D880 /* FlutterChannelsTest.m in Sources */,
0D52D3BD22C566D50011DEBD /* FlutterBinaryMessengerRelayTest.mm in Sources */,
Expand Down