From 7885e61e4f8770afe6ce8ef8b700b79bb717bd88 Mon Sep 17 00:00:00 2001 From: wangpw2 Date: Sun, 2 Apr 2023 21:19:11 +0800 Subject: [PATCH] fix ime bug for windows --- ..._editor_state_text_input_client_mixin.dart | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index 263bcc8c..5f98d56a 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -63,6 +63,8 @@ mixin RawEditorStateTextInputClientMixin on EditorState ); _updateSizeAndTransform(); + //update IME position for Windows + _updateComposingRectIfNeeded(); //update IME position for Macos _updateCaretRectIfNeeded(); _textInputConnection!.setEditingState(_lastKnownRemoteTextEditingValue!); @@ -70,18 +72,32 @@ mixin RawEditorStateTextInputClientMixin on EditorState _textInputConnection!.show(); } + void _updateComposingRectIfNeeded() { + final composingRange = _lastKnownRemoteTextEditingValue?.composing ?? + textEditingValue.composing; + if (hasConnection) { + assert(mounted); + final offset = composingRange.isValid ? composingRange.start : 0; + final composingRect = + renderEditor.getLocalRectForCaret(TextPosition(offset: offset)); + _textInputConnection!.setComposingRect(composingRect); + SchedulerBinding.instance + .addPostFrameCallback((_) => _updateComposingRectIfNeeded()); + } + } + void _updateCaretRectIfNeeded() { if (hasConnection) { if (renderEditor.selection.isValid && renderEditor.selection.isCollapsed) { - final TextPosition currentTextPosition = + final currentTextPosition = TextPosition(offset: renderEditor.selection.baseOffset); - final Rect caretRect = + final caretRect = renderEditor.getLocalRectForCaret(currentTextPosition); _textInputConnection!.setCaretRect(caretRect); } SchedulerBinding.instance - .addPostFrameCallback((Duration _) => _updateCaretRectIfNeeded()); + .addPostFrameCallback((_) => _updateCaretRectIfNeeded()); } }