diff --git a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index 1c3b92e5ef183..af86a3e9ec139 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -742,6 +742,18 @@ - (void)insertText:(id)string replacementRange:(NSRange)range { _activeModel->SetSelection(flutter::TextRange(base, extent)); } + else if (_activeModel->composing() && !(_activeModel->composing_range() == _activeModel->selection())) { + // When confirmed by Japanese IME, string replaces range of composing_range. + // If selection == composing_range there is no problem. + // If selection ! = composing_range the range of selection is only a part of composing_range. + // Since _activeModel->AddText is processed first for selection, the finalization of the conversion + // cannot be processed correctly unless selection == composing_range or selection.collapsed(). + // Since _activeModel->SetSelection fails if (composing_ && !range.collapsed()), + // selection == composing_range will failed. + // Therefore, the selection cursor should only be placed at the beginning of composing_range. + flutter::TextRange composing_range = _activeModel->composing_range(); + _activeModel->SetSelection(flutter::TextRange(composing_range.start())); + } flutter::TextRange oldSelection = _activeModel->selection(); flutter::TextRange composingBeforeChange = _activeModel->composing_range();