Add support for iOS UndoManager (flutter/engine#31415)
This commit is contained in:
@@ -1637,6 +1637,10 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInp
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUmbrellaImport.m
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerDelegate.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
|
||||
|
||||
@@ -84,6 +84,9 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterTextInputPlugin.mm",
|
||||
"framework/Source/FlutterUIPressProxy.h",
|
||||
"framework/Source/FlutterUIPressProxy.mm",
|
||||
"framework/Source/FlutterUndoManagerDelegate.h",
|
||||
"framework/Source/FlutterUndoManagerPlugin.h",
|
||||
"framework/Source/FlutterUndoManagerPlugin.mm",
|
||||
"framework/Source/FlutterView.h",
|
||||
"framework/Source/FlutterView.mm",
|
||||
"framework/Source/FlutterViewController.mm",
|
||||
@@ -262,6 +265,7 @@ shared_library("ios_test_flutter") {
|
||||
"framework/Source/FlutterPluginAppLifeCycleDelegateTest.mm",
|
||||
"framework/Source/FlutterRestorationPluginTest.mm",
|
||||
"framework/Source/FlutterTextInputPluginTest.mm",
|
||||
"framework/Source/FlutterUndoManagerPluginTest.mm",
|
||||
"framework/Source/FlutterViewControllerTest.mm",
|
||||
"framework/Source/SemanticsObjectTest.mm",
|
||||
"framework/Source/connection_collection_test.mm",
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerDelegate.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/connection_collection.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
|
||||
@@ -77,6 +79,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
@end
|
||||
|
||||
@interface FlutterEngine () <FlutterIndirectScribbleDelegate,
|
||||
FlutterUndoManagerDelegate,
|
||||
FlutterTextInputDelegate,
|
||||
FlutterBinaryMessenger>
|
||||
// Maintains a dictionary of plugin names that have registered with the engine. Used by
|
||||
@@ -107,6 +110,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
// Channels
|
||||
fml::scoped_nsobject<FlutterPlatformPlugin> _platformPlugin;
|
||||
fml::scoped_nsobject<FlutterTextInputPlugin> _textInputPlugin;
|
||||
fml::scoped_nsobject<FlutterUndoManagerPlugin> _undoManagerPlugin;
|
||||
fml::scoped_nsobject<FlutterRestorationPlugin> _restorationPlugin;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _localizationChannel;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _navigationChannel;
|
||||
@@ -114,6 +118,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _platformChannel;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _platformViewsChannel;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _textInputChannel;
|
||||
fml::scoped_nsobject<FlutterMethodChannel> _undoManagerChannel;
|
||||
fml::scoped_nsobject<FlutterBasicMessageChannel> _lifecycleChannel;
|
||||
fml::scoped_nsobject<FlutterBasicMessageChannel> _systemChannel;
|
||||
fml::scoped_nsobject<FlutterBasicMessageChannel> _settingsChannel;
|
||||
@@ -361,6 +366,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
self.iosPlatformView->SetOwnerViewController(_viewController);
|
||||
[self maybeSetupPlatformViewChannels];
|
||||
_textInputPlugin.get().viewController = viewController;
|
||||
_undoManagerPlugin.get().viewController = viewController;
|
||||
|
||||
if (viewController) {
|
||||
__block FlutterEngine* blockSelf = self;
|
||||
@@ -396,6 +402,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
- (void)notifyViewControllerDeallocated {
|
||||
[[self lifecycleChannel] sendMessage:@"AppLifecycleState.detached"];
|
||||
_textInputPlugin.get().viewController = nil;
|
||||
_undoManagerPlugin.get().viewController = nil;
|
||||
if (!_allowHeadlessExecution) {
|
||||
[self destroyContext];
|
||||
} else {
|
||||
@@ -433,6 +440,9 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
- (FlutterTextInputPlugin*)textInputPlugin {
|
||||
return _textInputPlugin.get();
|
||||
}
|
||||
- (FlutterUndoManagerPlugin*)undoManagerPlugin {
|
||||
return _undoManagerPlugin.get();
|
||||
}
|
||||
- (FlutterRestorationPlugin*)restorationPlugin {
|
||||
return _restorationPlugin.get();
|
||||
}
|
||||
@@ -451,6 +461,9 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
- (FlutterMethodChannel*)textInputChannel {
|
||||
return _textInputChannel.get();
|
||||
}
|
||||
- (FlutterMethodChannel*)undoManagerChannel {
|
||||
return _undoManagerChannel.get();
|
||||
}
|
||||
- (FlutterBasicMessageChannel*)lifecycleChannel {
|
||||
return _lifecycleChannel.get();
|
||||
}
|
||||
@@ -475,6 +488,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
_platformChannel.reset();
|
||||
_platformViewsChannel.reset();
|
||||
_textInputChannel.reset();
|
||||
_undoManagerChannel.reset();
|
||||
_lifecycleChannel.reset();
|
||||
_systemChannel.reset();
|
||||
_settingsChannel.reset();
|
||||
@@ -542,6 +556,11 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
binaryMessenger:self.binaryMessenger
|
||||
codec:[FlutterJSONMethodCodec sharedInstance]]);
|
||||
|
||||
_undoManagerChannel.reset([[FlutterMethodChannel alloc]
|
||||
initWithName:@"flutter/undomanager"
|
||||
binaryMessenger:self.binaryMessenger
|
||||
codec:[FlutterJSONMethodCodec sharedInstance]]);
|
||||
|
||||
_lifecycleChannel.reset([[FlutterBasicMessageChannel alloc]
|
||||
initWithName:@"flutter/lifecycle"
|
||||
binaryMessenger:self.binaryMessenger
|
||||
@@ -567,6 +586,10 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
textInputPlugin.indirectScribbleDelegate = self;
|
||||
[textInputPlugin setupIndirectScribbleInteraction:self.viewController];
|
||||
|
||||
FlutterUndoManagerPlugin* undoManagerPlugin =
|
||||
[[FlutterUndoManagerPlugin alloc] initWithDelegate:self];
|
||||
_undoManagerPlugin.reset(undoManagerPlugin);
|
||||
|
||||
_platformPlugin.reset([[FlutterPlatformPlugin alloc] initWithEngine:[self getWeakPtr]]);
|
||||
|
||||
_restorationPlugin.reset([[FlutterRestorationPlugin alloc]
|
||||
@@ -593,6 +616,12 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
[_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||
[textInputPlugin handleMethodCall:call result:result];
|
||||
}];
|
||||
|
||||
FlutterUndoManagerPlugin* undoManagerPlugin = _undoManagerPlugin.get();
|
||||
[_undoManagerChannel.get()
|
||||
setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||
[undoManagerPlugin handleMethodCall:call result:result];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,6 +986,14 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS
|
||||
arguments:@[ @(client) ]];
|
||||
}
|
||||
|
||||
#pragma mark - Undo Manager Delegate
|
||||
|
||||
- (void)flutterUndoManagerPlugin:(FlutterUndoManagerPlugin*)undoManagerPlugin
|
||||
handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
|
||||
NSString* action = (direction == FlutterUndoRedoDirectionUndo) ? @"undo" : @"redo";
|
||||
[_undoManagerChannel.get() invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]];
|
||||
}
|
||||
|
||||
#pragma mark - Screenshot Delegate
|
||||
|
||||
- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
|
||||
|
||||
@@ -45,6 +45,7 @@ static NSString* const kSetEditableSizeAndTransformMethod =
|
||||
@"TextInput.setEditableSizeAndTransform";
|
||||
static NSString* const kSetMarkedTextRectMethod = @"TextInput.setMarkedTextRect";
|
||||
static NSString* const kFinishAutofillContextMethod = @"TextInput.finishAutofillContext";
|
||||
static NSString* const kSetSelectionRectsMethod = @"TextInput.setSelectionRects";
|
||||
|
||||
#pragma mark - TextInputConfiguration Field Names
|
||||
static NSString* const kSecureTextEntry = @"obscureText";
|
||||
@@ -2085,7 +2086,7 @@ static BOOL IsSelectionRectCloserToPoint(CGPoint point,
|
||||
} else if ([method isEqualToString:kFinishAutofillContextMethod]) {
|
||||
[self triggerAutofillSave:[args boolValue]];
|
||||
result(nil);
|
||||
} else if ([method isEqualToString:@"TextInput.setSelectionRects"]) {
|
||||
} else if ([method isEqualToString:kSetSelectionRectsMethod]) {
|
||||
[self setSelectionRects:args];
|
||||
result(nil);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERDELEGATE_H_
|
||||
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERDELEGATE_H_
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSInteger, FlutterUndoRedoDirection) {
|
||||
FlutterUndoRedoDirectionUndo,
|
||||
FlutterUndoRedoDirectionRedo,
|
||||
};
|
||||
|
||||
@class FlutterUndoManagerPlugin;
|
||||
|
||||
@protocol FlutterUndoManagerDelegate <NSObject>
|
||||
- (void)flutterUndoManagerPlugin:(FlutterUndoManagerPlugin*)undoManagerPlugin
|
||||
handleUndoWithDirection:(FlutterUndoRedoDirection)direction;
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERDELEGATE_H_
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERPLUGIN_H_
|
||||
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERPLUGIN_H_
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "flutter/fml/memory/weak_ptr.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerDelegate.h"
|
||||
|
||||
@interface FlutterUndoManagerPlugin : NSObject
|
||||
|
||||
@property(nonatomic, assign) FlutterViewController* viewController;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<FlutterUndoManagerDelegate>)undoManagerDelegate
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
|
||||
|
||||
@end
|
||||
|
||||
#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERUNDOMANAGERPLUGIN_H_
|
||||
@@ -0,0 +1,114 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
#pragma mark - UndoManager channel method names.
|
||||
static NSString* const kSetUndoStateMethod = @"UndoManager.setUndoState";
|
||||
|
||||
#pragma mark - Undo State field names
|
||||
static NSString* const kCanUndo = @"canUndo";
|
||||
static NSString* const kCanRedo = @"canRedo";
|
||||
|
||||
@implementation FlutterUndoManagerPlugin {
|
||||
id<FlutterUndoManagerDelegate> _undoManagerDelegate;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id<FlutterUndoManagerDelegate>)undoManagerDelegate {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
// `_undoManagerDelegate` is a weak reference because it should retain FlutterUndoManagerPlugin.
|
||||
_undoManagerDelegate = undoManagerDelegate;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self resetUndoManager];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||
NSString* method = call.method;
|
||||
id args = call.arguments;
|
||||
if ([method isEqualToString:kSetUndoStateMethod]) {
|
||||
[self setUndoState:args];
|
||||
result(nil);
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUndoManager*)undoManager {
|
||||
return _viewController.undoManager;
|
||||
}
|
||||
|
||||
- (void)resetUndoManager API_AVAILABLE(ios(9.0)) {
|
||||
[[self undoManager] removeAllActionsWithTarget:self];
|
||||
}
|
||||
|
||||
- (void)registerUndoWithDirection:(FlutterUndoRedoDirection)direction API_AVAILABLE(ios(9.0)) {
|
||||
[[self undoManager] beginUndoGrouping];
|
||||
[[self undoManager] registerUndoWithTarget:self
|
||||
handler:^(id target) {
|
||||
// Register undo with opposite direction.
|
||||
FlutterUndoRedoDirection newDirection =
|
||||
(direction == FlutterUndoRedoDirectionRedo)
|
||||
? FlutterUndoRedoDirectionUndo
|
||||
: FlutterUndoRedoDirectionRedo;
|
||||
[target registerUndoWithDirection:newDirection];
|
||||
// Invoke method on delegate.
|
||||
[_undoManagerDelegate flutterUndoManagerPlugin:self
|
||||
handleUndoWithDirection:direction];
|
||||
}];
|
||||
[[self undoManager] endUndoGrouping];
|
||||
}
|
||||
|
||||
- (void)registerRedo API_AVAILABLE(ios(9.0)) {
|
||||
[[self undoManager] beginUndoGrouping];
|
||||
[[self undoManager]
|
||||
registerUndoWithTarget:self
|
||||
handler:^(id target) {
|
||||
// Register undo with opposite direction.
|
||||
[target registerUndoWithDirection:FlutterUndoRedoDirectionRedo];
|
||||
}];
|
||||
[[self undoManager] endUndoGrouping];
|
||||
[[self undoManager] undo];
|
||||
}
|
||||
|
||||
- (void)setUndoState:(NSDictionary*)dictionary API_AVAILABLE(ios(9.0)) {
|
||||
BOOL groupsByEvent = [self undoManager].groupsByEvent;
|
||||
[self undoManager].groupsByEvent = NO;
|
||||
BOOL canUndo = [dictionary[kCanUndo] boolValue];
|
||||
BOOL canRedo = [dictionary[kCanRedo] boolValue];
|
||||
|
||||
[self resetUndoManager];
|
||||
|
||||
if (canUndo) {
|
||||
[self registerUndoWithDirection:FlutterUndoRedoDirectionUndo];
|
||||
}
|
||||
if (canRedo) {
|
||||
[self registerRedo];
|
||||
}
|
||||
|
||||
if (_viewController.engine.textInputPlugin.textInputView != nil) {
|
||||
// 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];
|
||||
}
|
||||
[self undoManager].groupsByEvent = groupsByEvent;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,143 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
|
||||
|
||||
#import <OCMock/OCMock.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#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"
|
||||
|
||||
FLUTTER_ASSERT_ARC
|
||||
|
||||
@interface FlutterEngine ()
|
||||
- (nonnull FlutterUndoManagerPlugin*)undoManagerPlugin;
|
||||
@end
|
||||
|
||||
@interface FlutterUndoManagerPluginForTest : FlutterUndoManagerPlugin
|
||||
@property(nonatomic, assign) NSUndoManager* undoManager;
|
||||
@end
|
||||
|
||||
@implementation FlutterUndoManagerPluginForTest {
|
||||
}
|
||||
@end
|
||||
|
||||
@interface FlutterUndoManagerPluginTest : XCTestCase
|
||||
@property(nonatomic, strong) id engine;
|
||||
@property(nonatomic, strong) FlutterUndoManagerPluginForTest* undoManagerPlugin;
|
||||
@property(nonatomic, strong) FlutterViewController* viewController;
|
||||
@property(nonatomic, strong) NSUndoManager* undoManager;
|
||||
@end
|
||||
|
||||
@implementation FlutterUndoManagerPluginTest {
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
self.engine = OCMClassMock([FlutterEngine class]);
|
||||
|
||||
self.undoManagerPlugin = [[FlutterUndoManagerPluginForTest alloc] initWithDelegate:self.engine];
|
||||
|
||||
self.viewController = [FlutterViewController new];
|
||||
self.undoManagerPlugin.viewController = self.viewController;
|
||||
|
||||
self.undoManager = OCMClassMock([NSUndoManager class]);
|
||||
self.undoManagerPlugin.undoManager = self.undoManager;
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin];
|
||||
self.undoManagerPlugin = nil;
|
||||
self.engine = nil;
|
||||
self.viewController = nil;
|
||||
self.undoManager = nil;
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testSetUndoState {
|
||||
__block int registerUndoCount = 0;
|
||||
__block void (^undoHandler)(id target);
|
||||
OCMStub([self.undoManager registerUndoWithTarget:self.undoManagerPlugin handler:[OCMArg any]])
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
registerUndoCount++;
|
||||
__weak void (^handler)(id target);
|
||||
[invocation retainArguments];
|
||||
[invocation getArgument:&handler atIndex:3];
|
||||
undoHandler = handler;
|
||||
});
|
||||
__block int removeAllActionsCount = 0;
|
||||
OCMStub([self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin])
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
removeAllActionsCount++;
|
||||
});
|
||||
__block int delegateUndoCount = 0;
|
||||
OCMStub([self.engine flutterUndoManagerPlugin:[OCMArg any]
|
||||
handleUndoWithDirection:FlutterUndoRedoDirectionUndo])
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
delegateUndoCount++;
|
||||
});
|
||||
__block int delegateRedoCount = 0;
|
||||
OCMStub([self.engine flutterUndoManagerPlugin:[OCMArg any]
|
||||
handleUndoWithDirection:FlutterUndoRedoDirectionRedo])
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
delegateRedoCount++;
|
||||
});
|
||||
__block int undoCount = 0;
|
||||
OCMStub([self.undoManager undo]).andDo(^(NSInvocation* invocation) {
|
||||
undoCount++;
|
||||
undoHandler(self.undoManagerPlugin);
|
||||
});
|
||||
|
||||
// If canUndo and canRedo are false, only removeAllActionsWithTarget is called.
|
||||
FlutterMethodCall* setUndoStateCall =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
|
||||
arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
|
||||
[self.undoManagerPlugin handleMethodCall:setUndoStateCall
|
||||
result:^(id _Nullable result){
|
||||
}];
|
||||
XCTAssertEqual(1, removeAllActionsCount);
|
||||
XCTAssertEqual(0, registerUndoCount);
|
||||
|
||||
// If canUndo is true, an undo will be registered.
|
||||
setUndoStateCall =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
|
||||
arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
|
||||
[self.undoManagerPlugin handleMethodCall:setUndoStateCall
|
||||
result:^(id _Nullable result){
|
||||
}];
|
||||
XCTAssertEqual(2, removeAllActionsCount);
|
||||
XCTAssertEqual(1, registerUndoCount);
|
||||
|
||||
// Invoking the undo handler will invoke the handleUndo delegate method with "undo".
|
||||
undoHandler(self.undoManagerPlugin);
|
||||
XCTAssertEqual(1, delegateUndoCount);
|
||||
XCTAssertEqual(0, delegateRedoCount);
|
||||
XCTAssertEqual(2, registerUndoCount);
|
||||
|
||||
// Invoking the redo handler will invoke the handleUndo delegate method with "redo".
|
||||
undoHandler(self.undoManagerPlugin);
|
||||
XCTAssertEqual(1, delegateUndoCount);
|
||||
XCTAssertEqual(1, delegateRedoCount);
|
||||
XCTAssertEqual(3, registerUndoCount);
|
||||
|
||||
// If canRedo is true, an undo will be registered and undo will be called.
|
||||
setUndoStateCall =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
|
||||
arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
|
||||
[self.undoManagerPlugin handleMethodCall:setUndoStateCall
|
||||
result:^(id _Nullable result){
|
||||
}];
|
||||
XCTAssertEqual(3, removeAllActionsCount);
|
||||
XCTAssertEqual(5, registerUndoCount);
|
||||
XCTAssertEqual(1, undoCount);
|
||||
|
||||
// Invoking the redo handler will invoke the handleUndo delegate method with "redo".
|
||||
undoHandler(self.undoManagerPlugin);
|
||||
XCTAssertEqual(1, delegateUndoCount);
|
||||
XCTAssertEqual(2, delegateRedoCount);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -70,6 +70,7 @@
|
||||
0D6AB6CF22BB05E200EEE540 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
0D6AB73E22BD8F0200EEE540 /* FlutterEngineConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = FlutterEngineConfig.xcconfig; sourceTree = "<group>"; };
|
||||
68B6091227F62F990036AC78 /* VsyncWaiterIosTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VsyncWaiterIosTest.mm; sourceTree = "<group>"; };
|
||||
3DD7D38C27D2B81000DA365C /* FlutterUndoManagerPluginTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FlutterUndoManagerPluginTest.mm; sourceTree = "<group>"; };
|
||||
F7521D7226BB671E005F15C5 /* libios_test_flutter.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libios_test_flutter.dylib; path = "../../../../out/$(FLUTTER_ENGINE)/libios_test_flutter.dylib"; sourceTree = "<group>"; };
|
||||
F7521D7526BB673E005F15C5 /* libocmock_shared.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libocmock_shared.dylib; path = "../../../../out/$(FLUTTER_ENGINE)/libocmock_shared.dylib"; sourceTree = "<group>"; };
|
||||
F77E081726FA9CE6003E6E4C /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = "../../../../out/$(FLUTTER_ENGINE)/Flutter.framework"; sourceTree = "<group>"; };
|
||||
@@ -98,6 +99,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
68B6091227F62F990036AC78 /* VsyncWaiterIosTest.mm */,
|
||||
3DD7D38C27D2B81000DA365C /* FlutterUndoManagerPluginTest.mm */,
|
||||
F7A3FDE026B9E0A300EADD61 /* FlutterAppDelegateTest.mm */,
|
||||
0AC232F424BA71D300A85907 /* SemanticsObjectTest.mm */,
|
||||
0AC232F724BA71D300A85907 /* FlutterEngineTest.mm */,
|
||||
|
||||
Reference in New Issue
Block a user