8 #import <Foundation/Foundation.h>
9 #import <UIKit/UIKit.h>
11 #include "flutter/fml/logging.h"
13 #pragma mark - UndoManager channel method names.
16 #pragma mark - Undo State field names
21 id<FlutterUndoManagerDelegate> _undoManagerDelegate;
29 _undoManagerDelegate = undoManagerDelegate;
36 [
self resetUndoManager];
41 NSString* method = call.
method;
44 [
self setUndoState:args];
51 - (NSUndoManager*)undoManager {
56 [[
self undoManager] removeAllActionsWithTarget:self];
59 - (void)registerUndoWithDirection:(FlutterUndoRedoDirection)direction API_AVAILABLE(ios(9.0)) {
60 [[
self undoManager] beginUndoGrouping];
61 [[
self undoManager] registerUndoWithTarget:self
62 handler:^(id target) {
64 FlutterUndoRedoDirection newDirection =
65 (direction == FlutterUndoRedoDirectionRedo)
66 ? FlutterUndoRedoDirectionUndo
67 : FlutterUndoRedoDirectionRedo;
68 [target registerUndoWithDirection:newDirection];
70 [_undoManagerDelegate flutterUndoManagerPlugin:self
71 handleUndoWithDirection:direction];
73 [[
self undoManager] endUndoGrouping];
77 [[
self undoManager] beginUndoGrouping];
79 registerUndoWithTarget:self
80 handler:^(id target) {
82 [target registerUndoWithDirection:FlutterUndoRedoDirectionRedo];
84 [[
self undoManager] endUndoGrouping];
85 [[
self undoManager] undo];
88 - (void)setUndoState:(NSDictionary*)dictionary API_AVAILABLE(ios(9.0)) {
89 BOOL groupsByEvent = [
self undoManager].groupsByEvent;
90 [
self undoManager].groupsByEvent = NO;
91 BOOL canUndo = [dictionary[kCanUndo] boolValue];
92 BOOL canRedo = [dictionary[kCanRedo] boolValue];
94 [
self resetUndoManager];
97 [
self registerUndoWithDirection:FlutterUndoRedoDirectionUndo];
107 UITextInputAssistantItem* assistantItem =
108 _viewController.engine.textInputPlugin.textInputView.inputAssistantItem;
109 assistantItem.leadingBarButtonGroups = assistantItem.leadingBarButtonGroups;
111 [
self undoManager].groupsByEvent = groupsByEvent;