fix macos IME position bug using _textInputConnection!.setCaretRect(caretRect);

pull/1153/head
foreverpw 2 years ago
parent b389792002
commit 0e63ac312c
  1. 18
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -63,12 +63,28 @@ mixin RawEditorStateTextInputClientMixin on EditorState
);
_updateSizeAndTransform();
//update IME position for Macos
_updateCaretRectIfNeeded();
_textInputConnection!.setEditingState(_lastKnownRemoteTextEditingValue!);
}
_textInputConnection!.show();
}
void _updateCaretRectIfNeeded() {
if (hasConnection) {
if (renderEditor.selection.isValid &&
renderEditor.selection.isCollapsed) {
final TextPosition currentTextPosition =
TextPosition(offset: renderEditor.selection.baseOffset);
final Rect caretRect =
renderEditor.getLocalRectForCaret(currentTextPosition);
_textInputConnection!.setCaretRect(caretRect);
}
SchedulerBinding.instance
.addPostFrameCallback((Duration _) => _updateCaretRectIfNeeded());
}
}
/// Closes input connection if it's currently open. Otherwise does nothing.
void closeConnectionIfNeeded() {
if (!hasConnection) {

Loading…
Cancel
Save