[iOS] Remove selectionDidChange call in UndoManager (flutter/engine#45657)
Fixes https://github.com/flutter/flutter/issues/133424 The `-[TextInputDelegate selectionDidChange:]` call actually triggers some unwanted keyboard NLP actions that generate a bunch of candidates and automatically accept the first candidate. This causes `-[UITextInput setMarkedText:selection]` to be called with the first candidate and that inserts extraneous characters after the user types certain characters on the iPad software keyboard. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -104,9 +104,9 @@ static NSString* const kCanRedo = @"canRedo";
|
||||
// This is needed to notify the iPadOS keyboard that it needs to update the
|
||||
// state of the UIBarButtons. Otherwise, the state changes to NSUndoManager
|
||||
// will not show up until the next keystroke (or other trigger).
|
||||
id<UITextInputDelegate> inputDelegate =
|
||||
_viewController.engine.textInputPlugin.textInputView.inputDelegate;
|
||||
[inputDelegate selectionDidChange:_viewController.engine.textInputPlugin.textInputView];
|
||||
UITextInputAssistantItem* assistantItem =
|
||||
_viewController.engine.textInputPlugin.textInputView.inputAssistantItem;
|
||||
assistantItem.leadingBarButtonGroups = assistantItem.leadingBarButtonGroups;
|
||||
}
|
||||
[self undoManager].groupsByEvent = groupsByEvent;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
@interface FlutterEngine ()
|
||||
- (nonnull FlutterUndoManagerPlugin*)undoManagerPlugin;
|
||||
- (nonnull FlutterTextInputPlugin*)textInputPlugin;
|
||||
@end
|
||||
|
||||
@interface FlutterUndoManagerPluginForTest : FlutterUndoManagerPlugin
|
||||
@@ -50,7 +52,6 @@ FLUTTER_ASSERT_ARC
|
||||
|
||||
- (void)tearDown {
|
||||
[self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin];
|
||||
self.undoManagerPlugin = nil;
|
||||
self.engine = nil;
|
||||
self.viewController = nil;
|
||||
self.undoManager = nil;
|
||||
@@ -140,4 +141,26 @@ FLUTTER_ASSERT_ARC
|
||||
XCTAssertEqual(2, delegateRedoCount);
|
||||
}
|
||||
|
||||
- (void)testSetUndoStateDoesInteractWithInputDelegate {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/133424
|
||||
FlutterViewController* viewController = OCMPartialMock(self.viewController);
|
||||
self.undoManagerPlugin.viewController = self.viewController;
|
||||
|
||||
FlutterTextInputPlugin* textInputPlugin = OCMClassMock([FlutterTextInputPlugin class]);
|
||||
FlutterTextInputView* textInputView = OCMClassMock([FlutterTextInputView class]);
|
||||
|
||||
OCMStub([viewController engine]).andReturn(self.engine);
|
||||
OCMStub([self.engine textInputPlugin]).andReturn(textInputPlugin);
|
||||
OCMStub([textInputPlugin textInputView]).andReturn(textInputView);
|
||||
|
||||
FlutterMethodCall* setUndoStateCall =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
|
||||
arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
|
||||
[self.undoManagerPlugin handleMethodCall:setUndoStateCall
|
||||
result:^(id _Nullable result){
|
||||
}];
|
||||
|
||||
OCMVerify(never(), [textInputView inputDelegate]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user