From 110feacaa096ac8c149f99013945810a8e517dd6 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 30 Mar 2022 15:35:58 -0700 Subject: [PATCH 1/9] send correct composing region when composing text - deltas --- .../framework/Source/FlutterTextInputPlugin.mm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 92820541de369..d204b4a242a1e 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -570,19 +570,22 @@ - (void)insertText:(id)string replacementRange:(NSRange)range { } flutter::TextRange oldSelection = _activeModel->selection(); + flutter::TextRange composingBeforeChange = _activeModel->composing_range(); + flutter::TextRange replacedRange(-1,-1); std::string textBeforeChange = _activeModel->GetText().c_str(); std::string utf8String = [string UTF8String]; _activeModel->AddText(utf8String); if (_activeModel->composing()) { + replacedRange = composingBeforeChange; _activeModel->CommitComposing(); _activeModel->EndComposing(); + } else { + replacedRange = range.location == NSNotFound + ? flutter::TextRange(oldSelection.base(), oldSelection.extent()) + : flutter::TextRange(range.location, range.location + range.length); } if (_enableDeltaModel) { - flutter::TextRange replacedRange = - range.location == NSNotFound - ? flutter::TextRange(oldSelection.base(), oldSelection.extent()) - : flutter::TextRange(range.location, range.location + range.length); [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, replacedRange, utf8String)]; } else { @@ -625,6 +628,7 @@ - (void)setMarkedText:(id)string if (!_activeModel->composing()) { _activeModel->BeginComposing(); } + flutter::TextRange composingBeforeChange = _activeModel->composing_range(); // Input string may be NSString or NSAttributedString. BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; @@ -641,8 +645,7 @@ - (void)setMarkedText:(id)string _activeModel->SetSelection(flutter::TextRange(base, extent)); if (_enableDeltaModel) { - flutter::TextRange composing = _activeModel->composing_range(); - [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, composing, + [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, composingBeforeChange, marked_text)]; } else { [self updateEditState]; From ef12a52542845e28e6d0ddfa220984f96a644583 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 30 Mar 2022 15:38:35 -0700 Subject: [PATCH 2/9] formatting --- .../macos/framework/Source/FlutterTextInputPlugin.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index d204b4a242a1e..44349528339a3 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -571,7 +571,7 @@ - (void)insertText:(id)string replacementRange:(NSRange)range { flutter::TextRange oldSelection = _activeModel->selection(); flutter::TextRange composingBeforeChange = _activeModel->composing_range(); - flutter::TextRange replacedRange(-1,-1); + flutter::TextRange replacedRange(-1, -1); std::string textBeforeChange = _activeModel->GetText().c_str(); std::string utf8String = [string UTF8String]; @@ -582,8 +582,8 @@ - (void)insertText:(id)string replacementRange:(NSRange)range { _activeModel->EndComposing(); } else { replacedRange = range.location == NSNotFound - ? flutter::TextRange(oldSelection.base(), oldSelection.extent()) - : flutter::TextRange(range.location, range.location + range.length); + ? flutter::TextRange(oldSelection.base(), oldSelection.extent()) + : flutter::TextRange(range.location, range.location + range.length); } if (_enableDeltaModel) { [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, replacedRange, @@ -645,8 +645,8 @@ - (void)setMarkedText:(id)string _activeModel->SetSelection(flutter::TextRange(base, extent)); if (_enableDeltaModel) { - [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, composingBeforeChange, - marked_text)]; + [self updateEditStateWithDelta:flutter::TextEditingDelta(textBeforeChange, + composingBeforeChange, marked_text)]; } else { [self updateEditState]; } From 46fa5e77521022771e56b90b8461550eee01770e Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 10:06:51 -0700 Subject: [PATCH 3/9] logs --- .../macos/framework/Source/FlutterTextInputPlugin.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 44349528339a3..2a8061189ec60 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -411,6 +411,14 @@ - (void)updateEditStateWithDelta:(const flutter::TextEditingDelta)delta { int composingExtent = _activeModel->composing() ? _activeModel->composing_range().extent() : -1; NSString* const textAffinity = [self textAffinityString]; + NSLog(@"delta text: %s", delta.delta_text().c_str()); + NSLog(@"delta oldtext: %s", delta.old_text().c_str()); + NSLog(@"delta start: %d", delta.delta_start()); + NSLog(@"delta end: %d", delta.delta_end()); + NSLog(@"selection base: %lu", selectionBase); + NSLog(@"selection extent: %lu", selectionExtent); + NSLog(@"composing base: %d", composingBase); + NSLog(@"composing extent: %d", composingExtent); NSDictionary* deltaToFramework = @{ @"oldText" : @(delta.old_text().c_str()), From 1d9faa7ed62694a6dfa21398c31526c1f4b29b05 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 11:30:19 -0700 Subject: [PATCH 4/9] Add composing test and fix existing test --- .../Source/FlutterTextInputPluginTest.mm | 243 +++++++++++++++++- 1 file changed, 242 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 8bc3588d41cbc..0d7b484e0ce87 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -552,7 +552,7 @@ - (bool)testOperationsThatTriggerDelta { @"oldText" : @"text to insert", @"deltaText" : @"marked text", @"deltaStart" : @(14), - @"deltaEnd" : @(25), + @"deltaEnd" : @(14), @"selectionBase" : @(25), @"selectionExtent" : @(25), @"selectionAffinity" : @"TextAffinity.upstream", @@ -608,6 +608,243 @@ - (bool)testOperationsThatTriggerDelta { return true; } +- (bool)testComposingWithDelta { + 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", + @"enableDeltaModel" : @"true", + @"inputType" : @{@"name" : @"inputName"}, + } + ]] + result:^(id){ + }]; + [plugin setMarkedText:@"m" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"", + @"deltaText" : @"", + @"deltaStart" : @(0), + @"deltaEnd" : @(0), + @"selectionBase" : @(1), + @"selectionExtent" : @(1), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(1), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"ma" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"m", + @"deltaText" : @"ma", + @"deltaStart" : @(0), + @"deltaEnd" : @(1), + @"selectionBase" : @(2), + @"selectionExtent" : @(2), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(2), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"mar" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"ma", + @"deltaText" : @"mar", + @"deltaStart" : @(0), + @"deltaEnd" : @(2), + @"selectionBase" : @(3), + @"selectionExtent" : @(3), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(3), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"mark" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"mar", + @"deltaText" : @"mark", + @"deltaStart" : @(0), + @"deltaEnd" : @(3), + @"selectionBase" : @(4), + @"selectionExtent" : @(4), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(4), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"marke" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"mark", + @"deltaText" : @"marke", + @"deltaStart" : @(0), + @"deltaEnd" : @(4), + @"selectionBase" : @(5), + @"selectionExtent" : @(5), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(5), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"marked" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"marke", + @"deltaText" : @"marked", + @"deltaStart" : @(0), + @"deltaEnd" : @(5), + @"selectionBase" : @(6), + @"selectionExtent" : @(6), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(6), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin unmarkText]; + + deltaToFramework = @{ + @"oldText" : @"marked", + @"deltaText" : @"", + @"deltaStart" : @(-1), + @"deltaEnd" : @(-1), + @"selectionBase" : @(6), + @"selectionExtent" : @(6), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(-1), + @"composingExtent" : @(-1), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + return true; +} + - (bool)testLocalTextAndSelectionUpdateAfterDelta { id engineMock = OCMClassMock([FlutterEngine class]); id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); @@ -716,6 +953,10 @@ - (bool)testLocalTextAndSelectionUpdateAfterDelta { ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testOperationsThatTriggerDelta]); } +TEST(FlutterTextInputPluginTest, TestComposingWithDelta) { + ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testComposingWithDelta]); +} + TEST(FlutterTextInputPluginTest, TestLocalTextAndSelectionUpdateAfterDelta) { ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testLocalTextAndSelectionUpdateAfterDelta]); } From 94ac50ed866b01d6fcf0f1c9d16e2e44dc936199 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 11:41:57 -0700 Subject: [PATCH 5/9] formatting --- .../Source/FlutterTextInputPluginTest.mm | 294 +++++++++--------- 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 0d7b484e0ce87..1b64824297673 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -635,7 +635,7 @@ - (bool)testComposingWithDelta { }]; [plugin setMarkedText:@"m" selectedRange:NSMakeRange(0, 1)]; - deltaToFramework = @{ + NSDictionary* deltaToFramework = @{ @"oldText" : @"", @"deltaText" : @"", @"deltaStart" : @(0), @@ -647,6 +647,36 @@ - (bool)testComposingWithDelta { @"composingBase" : @(0), @"composingExtent" : @(1), }; + NSDictionary* expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + NSData* updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } + + [plugin setMarkedText:@"ma" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"m", + @"deltaText" : @"ma", + @"deltaStart" : @(0), + @"deltaEnd" : @(1), + @"selectionBase" : @(2), + @"selectionExtent" : @(2), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(2), + }; expectedState = @{ @"deltas" : @[ deltaToFramework ], }; @@ -663,155 +693,125 @@ - (bool)testComposingWithDelta { return false; } - [plugin setMarkedText:@"ma" selectedRange:NSMakeRange(0, 1)]; - - deltaToFramework = @{ - @"oldText" : @"m", - @"deltaText" : @"ma", - @"deltaStart" : @(0), - @"deltaEnd" : @(1), - @"selectionBase" : @(2), - @"selectionExtent" : @(2), - @"selectionAffinity" : @"TextAffinity.upstream", - @"selectionIsDirectional" : @(false), - @"composingBase" : @(0), - @"composingExtent" : @(2), - }; - expectedState = @{ - @"deltas" : @[ deltaToFramework ], - }; - - updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; - - @try { - OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) - [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); - } @catch (...) { - return false; - } - - [plugin setMarkedText:@"mar" selectedRange:NSMakeRange(0, 1)]; - - deltaToFramework = @{ - @"oldText" : @"ma", - @"deltaText" : @"mar", - @"deltaStart" : @(0), - @"deltaEnd" : @(2), - @"selectionBase" : @(3), - @"selectionExtent" : @(3), - @"selectionAffinity" : @"TextAffinity.upstream", - @"selectionIsDirectional" : @(false), - @"composingBase" : @(0), - @"composingExtent" : @(3), - }; - expectedState = @{ - @"deltas" : @[ deltaToFramework ], - }; - - updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; - - @try { - OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) - [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); - } @catch (...) { - return false; - } + [plugin setMarkedText:@"mar" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"ma", + @"deltaText" : @"mar", + @"deltaStart" : @(0), + @"deltaEnd" : @(2), + @"selectionBase" : @(3), + @"selectionExtent" : @(3), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(3), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } - [plugin setMarkedText:@"mark" selectedRange:NSMakeRange(0, 1)]; - - deltaToFramework = @{ - @"oldText" : @"mar", - @"deltaText" : @"mark", - @"deltaStart" : @(0), - @"deltaEnd" : @(3), - @"selectionBase" : @(4), - @"selectionExtent" : @(4), - @"selectionAffinity" : @"TextAffinity.upstream", - @"selectionIsDirectional" : @(false), - @"composingBase" : @(0), - @"composingExtent" : @(4), - }; - expectedState = @{ - @"deltas" : @[ deltaToFramework ], - }; - - updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; - - @try { - OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) - [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); - } @catch (...) { - return false; - } + [plugin setMarkedText:@"mark" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"mar", + @"deltaText" : @"mark", + @"deltaStart" : @(0), + @"deltaEnd" : @(3), + @"selectionBase" : @(4), + @"selectionExtent" : @(4), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(4), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } - [plugin setMarkedText:@"marke" selectedRange:NSMakeRange(0, 1)]; - - deltaToFramework = @{ - @"oldText" : @"mark", - @"deltaText" : @"marke", - @"deltaStart" : @(0), - @"deltaEnd" : @(4), - @"selectionBase" : @(5), - @"selectionExtent" : @(5), - @"selectionAffinity" : @"TextAffinity.upstream", - @"selectionIsDirectional" : @(false), - @"composingBase" : @(0), - @"composingExtent" : @(5), - }; - expectedState = @{ - @"deltas" : @[ deltaToFramework ], - }; - - updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; - - @try { - OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) - [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); - } @catch (...) { - return false; - } + [plugin setMarkedText:@"marke" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"mark", + @"deltaText" : @"marke", + @"deltaStart" : @(0), + @"deltaEnd" : @(4), + @"selectionBase" : @(5), + @"selectionExtent" : @(5), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(5), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } - [plugin setMarkedText:@"marked" selectedRange:NSMakeRange(0, 1)]; - - deltaToFramework = @{ - @"oldText" : @"marke", - @"deltaText" : @"marked", - @"deltaStart" : @(0), - @"deltaEnd" : @(5), - @"selectionBase" : @(6), - @"selectionExtent" : @(6), - @"selectionAffinity" : @"TextAffinity.upstream", - @"selectionIsDirectional" : @(false), - @"composingBase" : @(0), - @"composingExtent" : @(6), - }; - expectedState = @{ - @"deltas" : @[ deltaToFramework ], - }; - - updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; - - @try { - OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) - [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); - } @catch (...) { - return false; - } + [plugin setMarkedText:@"marked" selectedRange:NSMakeRange(0, 1)]; + + deltaToFramework = @{ + @"oldText" : @"marke", + @"deltaText" : @"marked", + @"deltaStart" : @(0), + @"deltaEnd" : @(5), + @"selectionBase" : @(6), + @"selectionExtent" : @(6), + @"selectionAffinity" : @"TextAffinity.upstream", + @"selectionIsDirectional" : @(false), + @"composingBase" : @(0), + @"composingExtent" : @(6), + }; + expectedState = @{ + @"deltas" : @[ deltaToFramework ], + }; + + updateCall = [[FlutterJSONMethodCodec sharedInstance] + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; + + @try { + OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) + [binaryMessengerMock sendOnChannel:@"flutter/textinput" message:updateCall]); + } @catch (...) { + return false; + } [plugin unmarkText]; From f6fea0622108eaeb88899f1749f8aa3e8eb02114 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 11:43:32 -0700 Subject: [PATCH 6/9] formatting --- .../framework/Source/FlutterTextInputPluginTest.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 1b64824297673..815d4d7c80b91 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -662,7 +662,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin setMarkedText:@"ma" selectedRange:NSMakeRange(0, 1)]; deltaToFramework = @{ @@ -692,7 +692,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin setMarkedText:@"mar" selectedRange:NSMakeRange(0, 1)]; deltaToFramework = @{ @@ -722,7 +722,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin setMarkedText:@"mark" selectedRange:NSMakeRange(0, 1)]; deltaToFramework = @{ @@ -752,7 +752,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin setMarkedText:@"marke" selectedRange:NSMakeRange(0, 1)]; deltaToFramework = @{ @@ -782,7 +782,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin setMarkedText:@"marked" selectedRange:NSMakeRange(0, 1)]; deltaToFramework = @{ @@ -812,7 +812,7 @@ - (bool)testComposingWithDelta { } @catch (...) { return false; } - + [plugin unmarkText]; deltaToFramework = @{ From 1ea900c7192902d55882ba47f12c493e6a65955d Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 11:45:25 -0700 Subject: [PATCH 7/9] Formatting --- .../macos/framework/Source/FlutterTextInputPluginTest.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 815d4d7c80b91..db882cd7b6824 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -712,9 +712,9 @@ - (bool)testComposingWithDelta { }; updateCall = [[FlutterJSONMethodCodec sharedInstance] - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" - arguments:@[ @(1), expectedState ]]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"TextInputClient.updateEditingStateWithDeltas" + arguments:@[ @(1), expectedState ]]]; @try { OCMVerify( // NOLINT(google-objc-avoid-throwing-exception) From 4e12b939b750b641168e0c4e04c77eb6dee80501 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 12:14:19 -0700 Subject: [PATCH 8/9] fix test --- .../darwin/macos/framework/Source/FlutterTextInputPluginTest.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index db882cd7b6824..17c50b26c5987 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -637,7 +637,7 @@ - (bool)testComposingWithDelta { NSDictionary* deltaToFramework = @{ @"oldText" : @"", - @"deltaText" : @"", + @"deltaText" : @"m", @"deltaStart" : @(0), @"deltaEnd" : @(0), @"selectionBase" : @(1), From a029e366179fdfb2329fe311bd05c4ae8915a717 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 31 Mar 2022 12:49:58 -0700 Subject: [PATCH 9/9] remove logs --- .../macos/framework/Source/FlutterTextInputPlugin.mm | 8 -------- 1 file changed, 8 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 2a8061189ec60..44349528339a3 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -411,14 +411,6 @@ - (void)updateEditStateWithDelta:(const flutter::TextEditingDelta)delta { int composingExtent = _activeModel->composing() ? _activeModel->composing_range().extent() : -1; NSString* const textAffinity = [self textAffinityString]; - NSLog(@"delta text: %s", delta.delta_text().c_str()); - NSLog(@"delta oldtext: %s", delta.old_text().c_str()); - NSLog(@"delta start: %d", delta.delta_start()); - NSLog(@"delta end: %d", delta.delta_end()); - NSLog(@"selection base: %lu", selectionBase); - NSLog(@"selection extent: %lu", selectionExtent); - NSLog(@"composing base: %d", composingBase); - NSLog(@"composing extent: %d", composingExtent); NSDictionary* deltaToFramework = @{ @"oldText" : @(delta.old_text().c_str()),