7 #pragma mark - UndoManager channel method names.
10 #pragma mark - Undo State field names
15 @property(nonatomic, weak, readonly) id<FlutterUndoManagerDelegate> undoManagerDelegate;
19 @property(nonatomic) NSUndoManager* undoManager;
28 _undoManagerDelegate = undoManagerDelegate;
35 [_undoManager removeAllActionsWithTarget:self];
39 NSString* method = call.
method;
42 self.undoManager =
self.undoManagerDelegate.undoManager;
43 [
self setUndoState:args];
50 - (void)resetUndoManager {
51 [
self.undoManager removeAllActionsWithTarget:self];
54 - (void)registerUndoWithDirection:(FlutterUndoRedoDirection)direction {
55 NSUndoManager* undoManager =
self.undoManager;
56 [undoManager beginUndoGrouping];
57 [undoManager registerUndoWithTarget:self
58 handler:^(FlutterUndoManagerPlugin* target) {
60 FlutterUndoRedoDirection newDirection =
61 (direction == FlutterUndoRedoDirectionRedo)
62 ? FlutterUndoRedoDirectionUndo
63 : FlutterUndoRedoDirectionRedo;
64 [target registerUndoWithDirection:newDirection];
66 [target.undoManagerDelegate handleUndoWithDirection:direction];
68 [undoManager endUndoGrouping];
71 - (void)registerRedo {
72 NSUndoManager* undoManager =
self.undoManager;
73 [undoManager beginUndoGrouping];
74 [undoManager registerUndoWithTarget:self
75 handler:^(id target) {
77 [target registerUndoWithDirection:FlutterUndoRedoDirectionRedo];
79 [undoManager endUndoGrouping];
83 - (void)setUndoState:(NSDictionary*)dictionary {
84 NSUndoManager* undoManager =
self.undoManager;
85 BOOL groupsByEvent = undoManager.groupsByEvent;
86 undoManager.groupsByEvent = NO;
87 BOOL canUndo = [dictionary[kCanUndo] boolValue];
88 BOOL canRedo = [dictionary[kCanRedo] boolValue];
90 [
self resetUndoManager];
93 [
self registerUndoWithDirection:FlutterUndoRedoDirectionUndo];
98 UIView<UITextInput>* textInputView =
self.undoManagerDelegate.activeTextInputView;
99 if (textInputView != nil) {
103 UITextInputAssistantItem* assistantItem = textInputView.inputAssistantItem;
104 assistantItem.leadingBarButtonGroups = assistantItem.leadingBarButtonGroups;
106 undoManager.groupsByEvent = groupsByEvent;