Repository navigation
fix: shield cursor rect during preedit to prevent IM candidate box jump - #737
Conversation
1. Root cause: during inputMethodEvent, undoing the previous preedit moves the cursor to a stale position before the new preedit is inserted; the input method (e.g. Sogou) queries cursorRect in this intermediate window and gets the wrong coordinate, causing the candidate box to jump left 2. Fix: wrap the undo+reinsert block in QSignalBlocker so updateMicroFocus signals are suppressed mid-update; cache the correct cursorRect before and after the block; override inputMethodQuery to return the cached rect while m_bInputMethodUpdating is true 3. Impact: only affects preedit rendering path; no API change, inputMethodQuery falls through to QPlainTextEdit when not updating Log: fix input method candidate box jumping left during preedit in text editor Influence: 1. Test preedit input with Sogou IME, verify candidate box stays in place 2. Test normal text input without IME, verify no regression 3. Test overwrite mode with IME preedit, verify cursor behavior correct fix: 屏蔽 preedit 期间光标坐标中间态,修复输入法候选框左跳 1. 根因:inputMethodEvent 中撤销上一次 preedit 后光标短暂处于旧 位置,新 preedit 插入前输入法(如搜狗)查询 cursorRect 拿到 错误坐标,导致候选框左跳 2. 方案:用 QSignalBlocker 包裹撤销+重新插入过程,屏蔽 updateMicroFocus 信号;在屏蔽前后缓存正确光标矩形;重写 inputMethodQuery 在 m_bInputMethodUpdating 期间返回缓存坐标 3. 影响:仅影响 preedit 渲染路径,无接口变更,非更新期间 inputMethodQuery 透传 QPlainTextEdit 默认实现 Log: 修复文本编辑器输入法 preedit 期间候选框左跳问题 Influence: 1. 使用搜狗输入法测试 preedit 输入,验证候选框位置不跳动 2. 测试无输入法的正常文本输入,验证无回归 3. 测试覆盖模式下输入法 preedit,验证光标行为正确 PMS: BUG-382615
Reviewer's GuideAPIAdd the
ImplementationShield preedit undo-and-reinsert updates with
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/editor/dtextedit.cpp" line_range="6640" />
<code_context>
- // 覆盖模式下输入法输入时,单独处理,模拟选中替换处理
+ // 用单独作用域包裹 QSignalBlocker,确保 updateMicroFocus 在解除屏蔽后调用
+ {
+ const QSignalBlocker blocker(this);
+
+ if (m_isPreeditBefore) {
</code_context>
<issue_to_address>
**IME edits leave editor state stale**
When an input-method event changes text, cursor, or selection, `QSignalBlocker(this)` suppresses `textChanged`, `cursorPositionChanged`, and `selectionChanged` during the undo and reinsertion, and destroying the blocker does not replay them. Word count, cursor and selection indicators, and cursor-dependent highlighting stay stale; the old selection range can also cause later bookmark and mark updates to remove or adjust the wrong items.
After unblocking, notify the affected text, cursor, and selection handlers and external consumers of the final editor state.
</issue_to_address>| // 覆盖模式下输入法输入时,单独处理,模拟选中替换处理 | ||
| // 用单独作用域包裹 QSignalBlocker,确保 updateMicroFocus 在解除屏蔽后调用 | ||
| { | ||
| const QSignalBlocker blocker(this); |
There was a problem hiding this comment.
🟡 Medium · IME edits leave editor state stale
When an input-method event changes text, cursor, or selection, QSignalBlocker(this) suppresses textChanged, cursorPositionChanged, and selectionChanged during the undo and reinsertion, and destroying the blocker does not replay them. Word count, cursor and selection indicators, and cursor-dependent highlighting stay stale; the old selection range can also cause later bookmark and mark updates to remove or adjust the wrong items.
After unblocking, notify the affected text, cursor, and selection handlers and external consumers of the final editor state.
Prompt for AI agents
In `src/editor/dtextedit.cpp` at line 6640:
**IME edits leave editor state stale**
When an input-method event changes text, cursor, or selection, `QSignalBlocker(this)` suppresses `textChanged`, `cursorPositionChanged`, and `selectionChanged` during the undo and reinsertion, and destroying the blocker does not replay them. Word count, cursor and selection indicators, and cursor-dependent highlighting stay stale; the old selection range can also cause later bookmark and mark updates to remove or adjust the wrong items.
After unblocking, notify the affected text, cursor, and selection handlers and external consumers of the final editor state.|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
merge |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
332bf12
into
linuxdeepin:release/eagle
fix: shield cursor rect during preedit to prevent IM candidate box jump
moves the cursor to a stale position before the new preedit is
inserted; the input method (e.g. Sogou) queries cursorRect in this
intermediate window and gets the wrong coordinate, causing the
candidate box to jump left
updateMicroFocus signals are suppressed mid-update; cache the
correct cursorRect before and after the block; override
inputMethodQuery to return the cached rect while
m_bInputMethodUpdating is true
inputMethodQuery falls through to QPlainTextEdit when not updating
Log: fix input method candidate box jumping left during preedit in text editor
Influence:
fix: 屏蔽 preedit 期间光标坐标中间态,修复输入法候选框左跳
位置,新 preedit 插入前输入法(如搜狗)查询 cursorRect 拿到
错误坐标,导致候选框左跳
updateMicroFocus 信号;在屏蔽前后缓存正确光标矩形;重写
inputMethodQuery 在 m_bInputMethodUpdating 期间返回缓存坐标
inputMethodQuery 透传 QPlainTextEdit 默认实现
Log: 修复文本编辑器输入法 preedit 期间候选框左跳问题
Influence:
PMS: BUG-382615
Summary by Sourcery
Stabilize input method candidate positioning during text preedit updates.
Bug Fixes:
Enhancements: