Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix: embedded image replaced by plain text unicode when adding Chinese text #2505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mchangtian wants to merge 2 commits into singerdmx:master
base: master
Choose a base branch
Loading
from mchangtian:fix-bug-issue#2503

Conversation

Copy link

@mchangtian mchangtian commented Mar 10, 2025
edited by CatHood0
Loading

Description

Fix cursor misalignment when inputting Chinese with Sogou Pinyin. Prevent images from being converted to obj after inserting Chinese text.

Image

Related Issues

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.

Type of Change

  • Feature: New functionality without breaking existing features.
  • 🛠️ Bug fix: Resolves an issue without altering current behavior.
  • 🧹 Refactor: Code reorganization, no behavior change.
  • Breaking: Alters existing functionality and requires updates.
  • 🧪 Tests: New or modified tests
  • 📝 Documentation: Updates or additions to documentation.
  • 🗑️ Chore: Routine tasks, or maintenance.
  • Build configuration change: Build/configuration changes.

CatHood0 and Metaildust reacted with thumbs up emoji
CatHood0

This comment was marked as resolved.

@CatHood0 CatHood0 added the enhancement New feature or request label Mar 10, 2025
@CatHood0 CatHood0 changed the title (削除) fix Inserting Chinese text after an image converts the image to 'obj' (削除ここまで) (追記) Fix: inserting Chinese text after an image converts the embed image to plain text unicode (追記ここまで) Mar 10, 2025
@CatHood0 CatHood0 changed the title (削除) Fix: inserting Chinese text after an image converts the embed image to plain text unicode (削除ここまで) (追記) Fix: embedded image replaced by plain text unicode when adding Chinese text (追記ここまで) Mar 10, 2025
Copy link
Collaborator

I'm going to test these changes as soon as I can to see if it doesn't damage or break anything (i.e. works for both Chinese and other languages)

singerdmx reacted with thumbs up emoji

Copy link
Collaborator

CatHood0 commented Mar 16, 2025
edited
Loading

@mchangtian could you test if this fix actually works on the web as well? That's where I get the most errors when using value.composing.end.

Note

For example, when I tried to select the line below while the cursor was in a Header block (shift+arrow down), it suddenly selected multiple lines at once, instead of just one. Once I removed value.composing.end, this didn't happen again (it only happens in web browsers).

Copy link
Author

@CatHood0 Based on my testing, the issue with embedded image replaced by plain text unicode when adding Chinese text does not occur in the web environment when using Sogou Pinyin Input Method, even without the value.composing.end check. This indicates that Sogou Pinyin operates differently in web browsers compared to other environments. Therefore, the proposed modification might not be necessary or applicable for web environments, and the original method should be retained there.

Regarding whether this modification is specific to the Windows environment, further testing is indeed required to confirm its scope. It would be beneficial to test across different platforms (e.g., macOS, Linux) and environments (e.g., desktop applications, mobile) to determine where the fix is truly needed. This will help ensure that the solution is both effective and appropriately targeted.

If you encounter any specific issues or need further assistance with testing, feel free to share more details.

CatHood0 reacted with thumbs up emoji

Copy link
Collaborator

To test this even better, I'll first merge PR #2512 into the main branch, and then add some test for the TextInputClient and editing aspect. This will prevent future errors if we need to modify the TextInputClient.

singerdmx and Metaildust reacted with thumbs up emoji

Copy link

@CatHood0 test please, it will be a big help

realth000 added a commit to realth000/flutter-quill that referenced this pull request Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@CatHood0 CatHood0 CatHood0 requested changes

@singerdmx singerdmx singerdmx approved these changes

@EchoEllet EchoEllet Awaiting requested review from EchoEllet

Labels

enhancement New feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Inserting Chinese text after an image converts the image to 'obj'

AltStyle によって変換されたページ (->オリジナル) /