Inserting Chinese text after an image converts the image to 'obj'
Have you checked for an existing issue?
- [x] I have searched the existing issues
Flutter Quill Version
11.0.0
Steps to Reproduce
When inserting Chinese text using an IME (Input Method Editor) after an embedded image in flutter_quill, the image gets converted to a plain "obj" string. This does NOT occur when typing English text after the image.
Environment
flutter_quill: 11.0.0 Device: windows 11 Input Method: Sogou Pinyin IME
Additional Notes from Reporter
I've attempted a potential fix by adjusting the cursor position calculation during IME composition. This modification appears to resolve the Chinese input issue specifically, but requires further validation:
lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart:199 void updateEditingValue(TextEditingValue value)
// modify by lonwan 2025年3月8日12:17:44 关键修正:动态计算光标位置, 解决输入中文时光标位置偏移问题
final effectiveCursorPosition = value.isComposingRangeValid
? value.composing.end
: value.selection.extentOffset;
final diff = getDiff(oldText, text, effectiveCursorPosition);
Expected results
The embedded image should remain intact when inserting Chinese text after it, just like when inserting English text.
Actual results
Inserting Chinese text after an image converts the image to 'obj'
Additional Context
Screenshots / Video demonstration
[Attach media here]
Logs
[Paste logs here]
It's related to SouGou IME, this issue does not occur with the OS bundled Microsoft Chinese IME.
I wonder where could we start to figure it out.
It's related to SouGou IME, this issue does not occur with the OS bundled Microsoft Chinese IME.
I wonder where could we start to figure it out. @realth000
What you're saying is true. I tried using Microsoft Pinyin to input Chinese and didn't find this problem. But Sogou Pinyin is very commonly used in China and should also be adapted.
Technical Context for Chinese IMEs
IME Composition Behavior
Chinese input methods like Sogou Pinyin use multi-step composition:
Users type phonetic text (e.g., "nihao") → IME shows candidate characters (e.g., "你好") During composition, the cursor position is managed by the IME's temporary text buffer. Unlike Microsoft Pinyin (which tightly integrates with OS-level text APIs), third-party IMEs like Sogou may not always synchronize composition ranges correctly with the framework.
Why This Fix Is Needed
Sogou Pinyin Issue:
During composition, selection.extentOffset might point to the phonetic input position (e.g., after "niha"), not the final character position. This causes cursor misalignment when text is committed.
Microsoft Pinyin Workaround:
It automatically adjusts cursor positions through OS-level text services, making explicit handling unnecessary.
Key Implementation Logic
isComposingRangeValid: Checks if the IME is in composition mode.
value.composing.end: Uses the end position of the IME's composition range instead of the default cursor position.
getDiff(): Calculates positional adjustments based on the actual committed text vs. intermediate composition state.
References for Further Discussion
- Composition event handling in browsers/editors.
- Cursor position workarounds for IMEs.
- IME-specific edge cases.
Let me know if you need a demo or additional technical details! 🛠️
Could you create a pull request describing the problem you are solving? Here's the contributing guide
If not, then I will create one myself to fix this problem.
Thank you for taking the time to check where the problem might be and fix it (even if only partially).
Ran into the same problem and the OBJ is displayed on the PC, pls is there a solution
@raopipi we are fixing it. But it needs more testing to avoid break default behavior for the other languages.
@raopipi If you're in a hurry, you can use my modified version first—it should address the issue. Regarding my changes, the PR has already been submitted, but further testing is still needed to avoid impacting other areas. I’m unsure how long it will take for it to be merged into the release version.
I've documented this bug fix in a CSDN blog post. If you're interested, feel free to check it out—my CSDN username is identical to my GitHub username.
@raopipi If you're in a hurry, you can use my modified version first—it should address the issue. Regarding my changes, the PR has already been submitted, but further testing is still needed to avoid impacting other areas. I’m unsure how long it will take for it to be merged into the release version. I've documented this bug fix in a CSDN blog post. If you're interested, feel free to check it out—my CSDN username is identical to my GitHub username.
Thank you very much, at the moment we are using it on the PC, let me take a look