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 1 commit
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 @@ -104,9 +104,11 @@ - (void)setUndoState:(NSDictionary*)dictionary API_AVAILABLE(ios(9.0)) {
// This is needed to notify the iPadOS keyboard that it needs to update the
Copy link
Contributor

Choose a reason for hiding this comment

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

is this comment still relevant?

// 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;
NSArray<UIBarButtonItemGroup*>* leadingGroups = assistantItem.leadingBarButtonGroups;
assistantItem.leadingBarButtonGroups = @[];
assistantItem.leadingBarButtonGroups = leadingGroups;
Copy link
Contributor

@hellohuanlin hellohuanlin Sep 14, 2023

Choose a reason for hiding this comment

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

hy is it setting leadingBarButtonGroups to empty array, and then setting back to the original value? Adding some comments here will be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was a workaround to notify the iPadOS keyboard to update the state of these buttons. It's been awhile, but I believe the behavior I was seeing was that state changes to canUndo/canRedo would not show up until the next keypress – so if I press a letter, the undo button should light up, but it won't until I press another key.

Copy link
Contributor

Choose a reason for hiding this comment

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

Worth trying if it works if we simply do assistantItem.leandingBarButtonGroups = assistantItem.leandingBarButtonGroups, in case apple doesn't check for no-ops in the setter.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW if it's iOS 17 related, feel free to contribute to the design doc which already discusses about several iOS 17 text input issues. It can be a good reference doc for future developers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the original issue is reproduced on an iOS 16 device so probably not ios specific.

I tested removing the intermediate empty array step it appears the setter indeed doesn't skip even when given the same array instance. Updated. I'll file a radar later since the keyboard could just rely on notifications to properly update the undo/redo UI.

}
[self undoManager].groupsByEvent = groupsByEvent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,7 +52,6 @@ - (void)setUp {

- (void)tearDown {
[self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin];
self.undoManagerPlugin = nil;
self.engine = nil;
self.viewController = nil;
self.undoManager = nil;
Expand Down Expand Up @@ -140,4 +141,26 @@ - (void)testSetUndoState {
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