Skip to content

fix: show input method on mouse release when terminal has focus#548

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jul 8, 2026
Merged

fix: show input method on mouse release when terminal has focus#548
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Explicitly call inputMethod()->show() after mouse release to ensure the IME panel appears for text entry in the terminal widget.

在终端窗口拥有焦点时,鼠标释放后显式调用 inputMethod()->show(),
确保输入法面板能够正常弹出。

Log: 鼠标释放后显示输入法
Influence: 终端在获得焦点并点击鼠标后能正常唤起输入法,改善中文等输入法的使用体验。

Summary by Sourcery

Bug Fixes:

  • Fix missing IME panel display after mouse release when the terminal display has focus to improve input method usability.

@sourcery-ai

sourcery-ai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures the terminal widget explicitly shows the input method editor (IME) panel on mouse release when the terminal has focus by invoking QInputMethod, improving IME behavior after mouse interactions.

Sequence diagram for showing IME on mouse release in terminal widget

sequenceDiagram
  actor User
  participant TerminalDisplay
  participant QApplication as qApp
  participant QInputMethod

  User->>TerminalDisplay: mouseReleaseEvent(ev)
  TerminalDisplay->>TerminalDisplay: mouseReleaseEvent(ev)
  alt hasFocus()
    TerminalDisplay->>qApp: inputMethod()
    qApp-->>TerminalDisplay: QInputMethod*
    TerminalDisplay->>QInputMethod: show()
  end
Loading

File-Level Changes

Change Details Files
Trigger IME panel display on mouse release when the terminal display has focus.
  • Include QInputMethod header to access the application input method
  • In mouseReleaseEvent, after ending drag operations, check if the terminal display has focus
  • If focused, call qApp->inputMethod()->show() to explicitly show the input method panel
3rdparty/terminalwidget/lib/TerminalDisplay.cpp

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

@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 left some high level feedback:

  • Consider guarding the qApp->inputMethod()->show(); call with a null check on qApp and inputMethod() to avoid potential crashes in edge cases where no input method is available.
  • If the IME should only be shown for text-related interactions, you may want to restrict the inputMethod()->show() call to specific mouse buttons (e.g., left-click) rather than all mouse release events while focused.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider guarding the `qApp->inputMethod()->show();` call with a null check on `qApp` and `inputMethod()` to avoid potential crashes in edge cases where no input method is available.
- If the IME should only be shown for text-related interactions, you may want to restrict the `inputMethod()->show()` call to specific mouse buttons (e.g., left-click) rather than all mouse release events while focused.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Explicitly call inputMethod()->show() after mouse release to ensure
the IME panel appears for text entry in the terminal widget.

在终端窗口拥有焦点时,鼠标释放后显式调用 inputMethod()->show(),
确保输入法面板能够正常弹出。

Log: 鼠标释放后显示输入法
Influence: 终端在获得焦点并点击鼠标后能正常唤起输入法,改善中文等输入法的使用体验。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:85分

■ 【总体评价】

代码正确修复了鼠标释放后虚拟输入法不弹出的缺陷,但缺少必要的代码注释
逻辑正确但因缺少注释说明修复意图扣15分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

在TerminalDisplay::mouseReleaseEvent函数2594-2596行,通过hasFocus()判断焦点状态后调用qApp->inputMethod()->show(),逻辑严谨,有效避免了在无焦点时无效调用输入法接口
建议:无需修改

  • 2.代码质量(一般)✕

在TerminalDisplay::mouseReleaseEvent函数中新增的输入法唤起逻辑缺乏注释说明,鼠标释放事件直接关联输入法弹出属于非直觉的补偿逻辑,后续维护者容易因不解其意图而误删
潜在问题:代码可维护性降低,意图不明确
建议:在if判断上方增加单行注释,说明此代码用于修复点击终端后输入法不弹出的问题

  • 3.代码性能(高效)✓

hasFocus()与inputMethod()->show()均为轻量级的Qt框架接口调用,不涉及耗时操作或额外资源开销
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
新增代码仅涉及UI层面的输入法状态切换,不处理任何外部输入、文件路径或系统命令,无攻击面
建议:无需修改

■ 【改进建议代码示例】

diff --git a/3rdparty/terminalwidget/lib/TerminalDisplay.cpp b/3rdparty/terminalwidget/lib/TerminalDisplay.cpp
index f90950b3..194a66d0 100644
--- a/3rdparty/terminalwidget/lib/TerminalDisplay.cpp
+++ b/3rdparty/terminalwidget/lib/TerminalDisplay.cpp
@@ -2593,6 +2593,10 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
                         charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , 2);
     }
     dragInfo.state = diNone;
+    // fix: 鼠标释放且获取焦点时,主动唤起虚拟输入法,解决点击终端后输入法不弹出的问题
+    if (hasFocus()) {
+        qApp->inputMethod()->show();
+    }
   }
 
   bool midClick = (ev->button() == MID_BTN);

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@wyu71 wyu71 merged commit 00c632e into linuxdeepin:master Jul 8, 2026
17 of 18 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