Skip to content

fix: shield cursor rect during preedit to prevent IM candidate box jump - #737

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:agent/bugfix/382615
Nov 19, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
GongHeng2017:agent/bugfix/382615

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

fix: shield cursor rect during preedit to prevent IM candidate box jump

  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

Summary by Sourcery

Stabilize input method candidate positioning during text preedit updates.

Bug Fixes:

  • Prevent input method candidate windows from jumping during preedit updates by shielding intermediate cursor coordinates.

Enhancements:

  • Preserve normal input method query behavior outside preedit updates while ensuring the final cursor position is refreshed after each update.

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
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Add the inputMethodQuery override and return the cached cursor rectangle for ImCursorRectangle during an input-method update, otherwise delegating to QPlainTextEdit.

  • src/editor/dtextedit.cpp L6690-6702
  • src/editor/dtextedit.h L581

Implementation

Shield preedit undo-and-reinsert updates with QSignalBlocker, cache the cursor rectangle around the update, and add the state used to prevent intermediate cursor coordinates from reaching the input method.

  • src/editor/dtextedit.cpp L6633-6688
  • src/editor/dtextedit.h L893-897

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@GongHeng2017
GongHeng2017 marked this pull request as draft November 18, 2026 08:56

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/editor/dtextedit.cpp
// 覆盖模式下输入法输入时,单独处理,模拟选中替换处理
// 用单独作用域包裹 QSignalBlocker,确保 updateMicroFocus 在解除屏蔽后调用
{
const QSignalBlocker blocker(this);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@GongHeng2017
GongHeng2017 marked this pull request as ready for review November 19, 2026 01:25
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017

Copy link
Copy Markdown
Contributor Author

merge

@GongHeng2017

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@GongHeng2017

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 332bf12 into linuxdeepin:release/eagle Nov 19, 2026
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants