3
3
// found in the LICENSE file.
4
4
5
5
#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
6
- #import " flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
7
-
8
- #import < Foundation/Foundation.h>
9
- #import < UIKit/UIKit.h>
10
-
11
- #include " flutter/fml/logging.h"
12
6
13
7
#pragma mark - UndoManager channel method names.
14
8
static NSString * const kSetUndoStateMethod = @" UndoManager.setUndoState" ;
17
11
static NSString * const kCanUndo = @" canUndo" ;
18
12
static NSString * const kCanRedo = @" canRedo" ;
19
13
20
- @implementation FlutterUndoManagerPlugin {
21
- id <FlutterUndoManagerDelegate> _undoManagerDelegate;
22
- }
14
+ @interface FlutterUndoManagerPlugin ()
15
+ @property (nonatomic , weak , readonly ) id <FlutterUndoManagerDelegate> undoManagerDelegate;
16
+ @end
17
+
18
+ @implementation FlutterUndoManagerPlugin
23
19
24
20
- (instancetype )initWithDelegate : (id <FlutterUndoManagerDelegate>)undoManagerDelegate {
25
21
self = [super init ];
26
22
27
23
if (self) {
28
- // `_undoManagerDelegate` is a weak reference because it should retain FlutterUndoManagerPlugin.
29
24
_undoManagerDelegate = undoManagerDelegate;
30
25
}
31
26
32
27
return self;
33
28
}
34
29
35
30
- (void )dealloc {
36
- [self resetUndoManager ];
37
- [super dealloc ];
31
+ [_undoManagerDelegate.undoManager removeAllActionsWithTarget: self ];
38
32
}
39
33
40
34
- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult)result {
@@ -48,46 +42,43 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
48
42
}
49
43
}
50
44
51
- - (NSUndoManager *)undoManager {
52
- return _viewController.undoManager ;
53
- }
54
-
55
- - (void )resetUndoManager API_AVAILABLE(ios(9.0 )) {
56
- [[self undoManager ] removeAllActionsWithTarget: self ];
45
+ - (void )resetUndoManager {
46
+ [self .undoManagerDelegate.undoManager removeAllActionsWithTarget: self ];
57
47
}
58
48
59
- - (void )registerUndoWithDirection : (FlutterUndoRedoDirection)direction API_AVAILABLE(ios( 9.0 )) {
60
- [[ self undoManager ] beginUndoGrouping ] ;
61
- [[ self undoManager ] registerUndoWithTarget: self
62
- handler: ^( id target) {
63
- // Register undo with opposite direction.
64
- FlutterUndoRedoDirection newDirection =
65
- (direction == FlutterUndoRedoDirectionRedo)
66
- ? FlutterUndoRedoDirectionUndo
67
- : FlutterUndoRedoDirectionRedo;
68
- [target registerUndoWithDirection: newDirection] ;
69
- // Invoke method on delegate.
70
- [_undoManagerDelegate flutterUndoManagerPlugin: self
71
- handleUndoWithDirection: direction];
72
- }];
73
- [[ self undoManager ] endUndoGrouping ];
49
+ - (void )registerUndoWithDirection : (FlutterUndoRedoDirection)direction {
50
+ NSUndoManager * undoManager = self. undoManagerDelegate . undoManager ;
51
+ [undoManager beginUndoGrouping ];
52
+ [undoManager registerUndoWithTarget: self
53
+ handler: ^(FlutterUndoManagerPlugin* target) {
54
+ // Register undo with opposite direction.
55
+ FlutterUndoRedoDirection newDirection =
56
+ (direction == FlutterUndoRedoDirectionRedo)
57
+ ? FlutterUndoRedoDirectionUndo
58
+ : FlutterUndoRedoDirectionRedo ;
59
+ [target registerUndoWithDirection: newDirection];
60
+ // Invoke method on delegate.
61
+ [target.undoManagerDelegate handleUndoWithDirection: direction];
62
+ }];
63
+ [undoManager endUndoGrouping ];
74
64
}
75
65
76
- - (void )registerRedo API_AVAILABLE(ios( 9.0 )) {
77
- [[ self undoManager ] beginUndoGrouping ] ;
78
- [[ self undoManager ]
79
- registerUndoWithTarget: self
80
- handler: ^(id target) {
81
- // Register undo with opposite direction.
82
- [target registerUndoWithDirection: FlutterUndoRedoDirectionRedo];
83
- }];
84
- [[ self undoManager ] endUndoGrouping ];
85
- [[ self undoManager ] undo ];
66
+ - (void )registerRedo {
67
+ NSUndoManager * undoManager = self. undoManagerDelegate . undoManager ;
68
+ [undoManager beginUndoGrouping ];
69
+ [undoManager registerUndoWithTarget: self
70
+ handler: ^(id target) {
71
+ // Register undo with opposite direction.
72
+ [target registerUndoWithDirection: FlutterUndoRedoDirectionRedo];
73
+ }];
74
+ [undoManager endUndoGrouping ];
75
+ [undoManager undo ];
86
76
}
87
77
88
- - (void )setUndoState : (NSDictionary *)dictionary API_AVAILABLE(ios(9.0 )) {
89
- BOOL groupsByEvent = [self undoManager ].groupsByEvent ;
90
- [self undoManager ].groupsByEvent = NO ;
78
+ - (void )setUndoState : (NSDictionary *)dictionary {
79
+ NSUndoManager * undoManager = self.undoManagerDelegate .undoManager ;
80
+ BOOL groupsByEvent = undoManager.groupsByEvent ;
81
+ undoManager.groupsByEvent = NO ;
91
82
BOOL canUndo = [dictionary[kCanUndo ] boolValue ];
92
83
BOOL canRedo = [dictionary[kCanRedo ] boolValue ];
93
84
@@ -99,16 +90,15 @@ - (void)setUndoState:(NSDictionary*)dictionary API_AVAILABLE(ios(9.0)) {
99
90
if (canRedo) {
100
91
[self registerRedo ];
101
92
}
102
-
103
- if (_viewController. engine . textInputPlugin . textInputView != nil ) {
93
+ UIView<UITextInput>* textInputView = self. undoManagerDelegate . activeTextInputView ;
94
+ if (textInputView != nil ) {
104
95
// This is needed to notify the iPadOS keyboard that it needs to update the
105
96
// state of the UIBarButtons. Otherwise, the state changes to NSUndoManager
106
97
// will not show up until the next keystroke (or other trigger).
107
- UITextInputAssistantItem* assistantItem =
108
- _viewController.engine .textInputPlugin .textInputView .inputAssistantItem ;
98
+ UITextInputAssistantItem* assistantItem = textInputView.inputAssistantItem ;
109
99
assistantItem.leadingBarButtonGroups = assistantItem.leadingBarButtonGroups ;
110
100
}
111
- [ self undoManager ] .groupsByEvent = groupsByEvent;
101
+ undoManager.groupsByEvent = groupsByEvent;
112
102
}
113
103
114
104
@end
0 commit comments