Repository navigation
fix: insert IME composing text at the offset reported by the delta - #1250
Open
Ultra-Logos wants to merge 1 commit into
Open
Ultra-Logos wants to merge 1 commit into
Ultra-Logos wants to merge 1 commit into
Conversation
Some IMEs (fcitx5 on Linux) report the selection at the start of the preedit while the composing range spans the whole preedit. Inserting at the editor selection then prepends every new character to the preedit, the editor text drifts from the platform IME model and the corrective setEditingState drops or duplicates characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
While an IME composition is active,
onInsertinserts the new text at the editor selection instead of atTextEditingDeltaInsertion.insertionOffset.Some IMEs report the selection at the start of the preedit while
composingspans the whole preedit. fcitx5 on Linux (Rime engine) does exactly this:" 这是"1(start of the preedit)[1, 3]insertionOffset2The editor inserts at offset
0, so the node text becomes是这. It no longer matches the platform IME model,KeyboardServiceWidget._attachTextInputServicetherefore pushes a corrected value throughsetEditingState, and the following updates drop, reorder or duplicate characters in the document.Same failure mode as #696 (Sogou on Windows): characters arrive out of order and keep leaking into the document while the IME caret stays at the beginning of the preedit.
Fix
Insert at the offset reported by the delta while composing, and keep
afterSelectionat the position reported by the IME — moving the selection would trigger the samesetEditingStateresync.Regular typing is untouched: collapsed composing ranges still insert at the selection, and for IMEs that keep the caret at the end of the preedit both offsets are identical.
Tests
New widget test in
test/new/service/ime/delta_input_on_insert_impl_test.dartreplays an fcitx5 preedit sequence (" 这"→" 这是", caret always at the preedit start) and asserts the node text is这是:Expected: 这是 / Actual: 是这The existing
delta input insert - widget testcases still pass.Fixes #696