Send -1 for empty composition range (flutter/engine#24865)
https://github.com/flutter/flutter/issues/77600
This commit is contained in:
@@ -1148,6 +1148,7 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfa
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextureRegistrar.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterTextureRegistrar.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h
|
||||
|
||||
@@ -165,6 +165,7 @@ executable("flutter_desktop_darwin_unittests") {
|
||||
"framework/Source/FlutterMetalSurfaceManagerTest.mm",
|
||||
"framework/Source/FlutterOpenGLRendererTest.mm",
|
||||
"framework/Source/FlutterPlatformNodeDelegateMacTest.mm",
|
||||
"framework/Source/FlutterTextInputPluginTest.mm",
|
||||
"framework/Source/FlutterViewControllerTest.mm",
|
||||
"framework/Source/FlutterViewControllerTestUtils.h",
|
||||
"framework/Source/FlutterViewControllerTestUtils.mm",
|
||||
|
||||
@@ -25,3 +25,8 @@
|
||||
- (instancetype)initWithViewController:(FlutterViewController*)viewController;
|
||||
|
||||
@end
|
||||
|
||||
// Private methods made visible for testing
|
||||
@interface FlutterTextInputPlugin (TestMethods)
|
||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
|
||||
@end
|
||||
|
||||
@@ -227,13 +227,17 @@ static flutter::TextRange RangeFromBaseExtent(NSNumber* base,
|
||||
NSString* const textAffinity = (self.textAffinity == FlutterTextAffinityUpstream)
|
||||
? kTextAffinityUpstream
|
||||
: kTextAffinityDownstream;
|
||||
|
||||
int composingBase = _activeModel->composing() ? _activeModel->composing_range().base() : -1;
|
||||
int composingExtent = _activeModel->composing() ? _activeModel->composing_range().extent() : -1;
|
||||
|
||||
NSDictionary* state = @{
|
||||
kSelectionBaseKey : @(_activeModel->selection().base()),
|
||||
kSelectionExtentKey : @(_activeModel->selection().extent()),
|
||||
kSelectionAffinityKey : textAffinity,
|
||||
kSelectionIsDirectionalKey : @NO,
|
||||
kComposingBaseKey : @(_activeModel->composing_range().base()),
|
||||
kComposingExtentKey : @(_activeModel->composing_range().extent()),
|
||||
kComposingBaseKey : @(composingBase),
|
||||
kComposingExtentKey : @(composingExtent),
|
||||
kTextKey : [NSString stringWithUTF8String:_activeModel->GetText().c_str()]
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// 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/macos/framework/Headers/FlutterViewController.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
|
||||
|
||||
#import <OCMock/OCMock.h>
|
||||
#import "flutter/testing/testing.h"
|
||||
|
||||
@interface FlutterInputPluginTestObjc : NSObject
|
||||
- (bool)testEmptyCompositionRange;
|
||||
@end
|
||||
|
||||
@implementation FlutterInputPluginTestObjc
|
||||
|
||||
- (bool)testEmptyCompositionRange {
|
||||
id engineMock = OCMClassMock([FlutterEngine class]);
|
||||
id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
|
||||
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
|
||||
[engineMock binaryMessenger])
|
||||
.andReturn(binaryMessengerMock);
|
||||
|
||||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
|
||||
nibName:@""
|
||||
bundle:nil];
|
||||
|
||||
FlutterTextInputPlugin* plugin =
|
||||
[[FlutterTextInputPlugin alloc] initWithViewController:viewController];
|
||||
|
||||
[plugin handleMethodCall:[FlutterMethodCall
|
||||
methodCallWithMethodName:@"TextInput.setClient"
|
||||
arguments:@[
|
||||
@(1), @{
|
||||
@"inputAction" : @"action",
|
||||
@"inputType" : @{@"name" : @"inputName"},
|
||||
}
|
||||
]]
|
||||
result:^(id){
|
||||
}];
|
||||
|
||||
FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setEditingState"
|
||||
arguments:@{
|
||||
@"text" : @"Text",
|
||||
@"selectionBase" : @(0),
|
||||
@"selectionExtent" : @(0),
|
||||
@"composingBase" : @(-1),
|
||||
@"composingExtent" : @(-1),
|
||||
}];
|
||||
|
||||
NSDictionary* expectedState = @{
|
||||
@"selectionBase" : @(0),
|
||||
@"selectionExtent" : @(0),
|
||||
@"selectionAffinity" : @"TextAffinity.upstream",
|
||||
@"selectionIsDirectional" : @(NO),
|
||||
@"composingBase" : @(-1),
|
||||
@"composingExtent" : @(-1),
|
||||
@"text" : @"Text",
|
||||
};
|
||||
|
||||
NSData* updateCall = [[FlutterJSONMethodCodec sharedInstance]
|
||||
encodeMethodCall:[FlutterMethodCall
|
||||
methodCallWithMethodName:@"TextInputClient.updateEditingState"
|
||||
arguments:@[ @(1), expectedState ]]];
|
||||
|
||||
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
|
||||
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
|
||||
|
||||
[plugin handleMethodCall:call
|
||||
result:^(id){
|
||||
}];
|
||||
|
||||
@try {
|
||||
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
|
||||
[binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]);
|
||||
} @catch (...) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace flutter::testing {
|
||||
|
||||
TEST(FlutterTextInputPluginTest, TestEmptyCompositionRange) {
|
||||
ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testEmptyCompositionRange]);
|
||||
}
|
||||
|
||||
} // namespace flutter::testing
|
||||
Reference in New Issue
Block a user