Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
static NSString* const kKeyboardAppearance = @"keyboardAppearance";
static NSString* const kInputAction = @"inputAction";
static NSString* const kEnableDeltaModel = @"enableDeltaModel";
static NSString* const kEnableInteractiveSelection = @"enableInteractiveSelection";

static NSString* const kSmartDashesType = @"smartDashesType";
static NSString* const kSmartQuotesType = @"smartQuotesType";
Expand Down Expand Up @@ -732,6 +733,7 @@ @implementation FlutterTextInputView {
// The view has reached end of life, and is no longer
// allowed to access its textInputDelegate.
BOOL _decommissioned;
bool _enableInteractiveSelection;
}

@synthesize tokenizer = _tokenizer;
Expand Down Expand Up @@ -765,6 +767,7 @@ - (instancetype)initWithOwner:(FlutterTextInputPlugin*)textInputPlugin {
_returnKeyType = UIReturnKeyDone;
_secureTextEntry = NO;
_enableDeltaModel = NO;
_enableInteractiveSelection = YES;
_accessibilityEnabled = NO;
_decommissioned = NO;
if (@available(iOS 11.0, *)) {
Expand Down Expand Up @@ -796,7 +799,7 @@ - (void)configureWithDictionary:(NSDictionary*)configuration {
self.keyboardType = ToUIKeyboardType(inputType);
self.returnKeyType = ToUIReturnKeyType(configuration[kInputAction]);
self.autocapitalizationType = ToUITextAutoCapitalizationType(configuration);

_enableInteractiveSelection = [configuration[kEnableInteractiveSelection] boolValue];
if (@available(iOS 11.0, *)) {
NSString* smartDashesType = configuration[kSmartDashesType];
// This index comes from the SmartDashesType enum in the framework.
Expand Down Expand Up @@ -1115,6 +1118,10 @@ - (void)setSelectedTextRangeLocal:(UITextRange*)selectedTextRange {
}

- (void)setSelectedTextRange:(UITextRange*)selectedTextRange {
if (!_enableInteractiveSelection) {
return;
}

[self setSelectedTextRangeLocal:selectedTextRange];

if (_enableDeltaModel) {
Expand Down Expand Up @@ -1740,7 +1747,6 @@ - (void)updateEditingState {
composingBase = ((FlutterTextPosition*)self.markedTextRange.start).index;
composingExtent = ((FlutterTextPosition*)self.markedTextRange.end).index;
}

NSDictionary* state = @{
@"selectionBase" : @(selectionBase),
@"selectionExtent" : @(selectionExtent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (void)setMarkedRect:(CGRect)markedRect;
- (void)updateEditingState;
- (BOOL)isVisibleToAutofill;
- (id<FlutterTextInputDelegate>)textInputDelegate;

- (void)configureWithDictionary:(NSDictionary*)configuration;
@end

@interface FlutterTextInputViewSpy : FlutterTextInputView
Expand Down Expand Up @@ -139,7 +139,8 @@ - (NSMutableDictionary*)mutableTemplateCopy {
@"inputAction" : @"TextInputAction.unspecified",
@"smartDashesType" : @"0",
@"smartQuotesType" : @"0",
@"autocorrect" : @YES
@"autocorrect" : @YES,
@"enableInteractiveSelection" : @YES,
};
}

Expand Down Expand Up @@ -269,6 +270,34 @@ - (void)testAutocorrectionPromptRectAppears {
withClient:0]);
}

- (void)testIngoresSelectionChangeIfSelectionIsDisabled {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
__block int updateCount = 0;
OCMStub([engine flutterTextInputView:inputView updateEditingClient:0 withState:[OCMArg isNotNil]])
.andDo(^(NSInvocation* invocation) {
updateCount++;
});

[inputView.text setString:@"Some initial text"];
XCTAssertEqual(updateCount, 0);

FlutterTextRange* textRange = [FlutterTextRange rangeWithNSRange:NSMakeRange(0, 1)];
[inputView setSelectedTextRange:textRange];
XCTAssertEqual(updateCount, 1);

// Disable the interactive selection.
NSDictionary* config = self.mutableTemplateCopy;
[config setValue:@(NO) forKey:@"enableInteractiveSelection"];
[config setValue:@(NO) forKey:@"obscureText"];
[config setValue:@(NO) forKey:@"enableDeltaModel"];
[inputView configureWithDictionary:config];

textRange = [FlutterTextRange rangeWithNSRange:NSMakeRange(2, 3)];
[inputView setSelectedTextRange:textRange];
// The update count does not change.
XCTAssertEqual(updateCount, 1);
}

- (void)testAutocorrectionPromptRectDoesNotAppearDuringScribble {
if (@available(iOS 14.0, *)) {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
Expand Down