Skip to content

fix: notify input method of cursor change after terminal image update - #599

Draft
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383823
Draft

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383823

Conversation

@add-uos

@add-uos add-uos commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

TerminalDisplay::updateImage() is called after terminal content changes (line breaks, scrolling). The function only calls update() (widget repaint) at the end but never calls qApp->inputMethod()->update(Qt::ImQueryAll) to notify the IME framework that the cursor rectangle has changed. The IME framework (fcitx5) depends on this notification to re-query ImCursorRectangle; without it, the candidate box is positioned at the stale cursor location.

Key evidence: defect at 3rdparty/terminalwidget/lib/TerminalDisplay.cpp:1324 — updateImage() lacks inputMethod()->update() after update(). Same file line 2602 (mouseReleaseEvent) already has qApp->inputMethod()->show(), confirming this is an established pattern that updateImage() path missed.

Fix

Add qApp->inputMethod()->update(Qt::ImQueryAll) with null check after update() in updateImage(), so the IME framework re-queries the cursor rectangle and positions the candidate box correctly after terminal content updates.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line update() (line 1324) was introduced by commit 24a40d79 (2020), not a product of an IME-related fix; this change does not revert any historical fix
  • No function signature change, no public member modification; all callers of updateImage() unaffected
  • Pattern qApp->inputMethod() already used at line 2602 in the same file

Business Impact Scope

Terminal IME interaction: the pinyin IME candidate box position now follows the cursor after line breaks and scrolling. Affected callers: all paths invoking TerminalDisplay::updateImage() (outputChanged signal, scrollbar, keyboard events) — none require modification as only an internal API call was added.

Verification Suggestion

Test pinyin input after multiple line breaks in terminal; test pinyin input after terminal scroll output; verify no regression on mouse-click cursor positioning.


根因分析

TerminalDisplay::updateImage() 在终端内容更新(换行、滚动)后被调用。函数末尾仅调用 update()(widget 重绘),但未调用 qApp->inputMethod()->update(Qt::ImQueryAll) 通知输入法框架光标矩形已变更。输入法框架(fcitx5)依赖该通知触发重新查询 ImCursorRectangle,缺少此调用时使用过期的光标位置定位候选框,导致候选框停留在旧位置。

关键证据:缺陷位于 3rdparty/terminalwidget/lib/TerminalDisplay.cpp:1324,updateImage() 的 update() 之后缺少 inputMethod()->update() 调用。同文件 line 2602(mouseReleaseEvent)已有 qApp->inputMethod()->show() 调用,说明输入法通知是既有模式,updateImage() 路径遗漏了。

修复方案

在 updateImage() 的 update() 调用之后,新增带空指针保护的 qApp->inputMethod()->update(Qt::ImQueryAll) 调用,使输入法框架在终端内容更新后重新查询光标矩形,正确定位候选框。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行 update()(line 1324)由 commit 24a40d79(2020)引入,非输入法相关修复产物,本次改动不撤销任何历史修复
  • 无函数签名变更、无公开成员修改;updateImage() 所有调用者不受影响
  • qApp->inputMethod() 模式在同文件 line 2602 已有使用

业务影响范围

终端输入法交互:拼音输入法候选框在换行和滚动后正确跟随光标位置。受影响调用者:TerminalDisplay::updateImage() 的所有调用路径(outputChanged 信号、滚动条、键盘事件),均无需修改——仅内部新增 API 调用。

验证建议

测试终端中输入拼音后多次回车再输入拼音,验证候选框跟随光标;测试终端滚动后输入拼音候选框位置正确;验证鼠标点击移动光标后输入拼音无回归。

PMS: BUG-383823

Summary by Sourcery

Bug Fixes:

  • Notify the input method framework after terminal image updates so candidate windows track the current cursor position following content changes such as line breaks and scrolling.

1. Root cause: TerminalDisplay::updateImage() only calls update() to
   repaint the widget after terminal content changes (line breaks,
   scrolling), but never calls qApp->inputMethod()->update() to notify
   the IME framework that the cursor rectangle has changed
2. Fix: add qApp->inputMethod()->update(Qt::ImQueryAll) with null check
   after update() in updateImage(), so the IME framework re-queries
   ImCursorRectangle and positions the candidate box correctly
3. Impact: pinyin IME candidate box now follows the cursor after line
   breaks and scrolling; no behavior change when no input method is
   active

Log: fix pinyin IME candidate box not following cursor after line breaks

Influence:
1. Test pinyin input after multiple line breaks in terminal
2. Test pinyin input after terminal scroll output
3. Verify no regression on mouse-click cursor positioning

fix: 修复终端内容更新后输入法候选框不跟随光标位置

1. 根因:TerminalDisplay::updateImage() 在终端内容更新(换行、滚动)
   后仅调用 update() 重绘控件,未调用 qApp->inputMethod()->update()
   通知输入法框架光标矩形已变更
2. 方案:在 updateImage() 的 update() 之后新增带空指针保护的
   qApp->inputMethod()->update(Qt::ImQueryAll) 调用,使输入法框架
   重新查询 ImCursorRectangle 并正确定位候选框
3. 影响:拼音输入法候选框在换行和滚动后正确跟随光标位置;无输入法
   时无行为变化

Log: 修复拼音输入法候选框在换行后不跟随光标的问题

Influence:
1. 测试终端中输入拼音后多次回车再输入拼音,验证候选框跟随光标
2. 测试终端滚动输出后输入拼音,验证候选框位置正确
3. 验证鼠标点击移动光标后输入拼音无回归

PMS: BUG-383823
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Notify the active input method after the terminal image updates so it can re-query the cursor rectangle.

  • 3rdparty/terminalwidget/lib/TerminalDisplay.cpp L1327-1330

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

@add-uos
add-uos marked this pull request as draft November 20, 2026 13:53

@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 reviewed your changes and they look great!


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

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.

2 participants