Skip to content

fix: guard displayShortcuts against key auto-repeat - #741

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

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

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In Window::keyPressEvent, the displayshortcuts shortcut branch calls displayShortcuts() without checking QKeyEvent::isAutoRepeat(). When the user holds Ctrl+Shift+?, Qt generates auto-repeat KeyPress events at ~10–30 Hz, each triggering displayShortcuts(), which in turn calls QProcess::startDetached("deepin-shortcut-viewer") every time. Multiple viewer instances compete for window focus; the newly launched instance steals focus from the previous one, causing it to close — resulting in the preview "flashing by" (source: window.cpp:4587–4589, window.cpp:2691–2692).

Fix

Add an isAutoRepeat() early-return guard before the displayShortcuts() call in the displayshortcuts branch of keyPressEvent. Only the initial key press triggers the shortcut viewer; auto-repeat events are ignored. This matches the root-cause fix recommended in the analysis report (section 10).

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target lines (4587–4592) were last modified by a style cleanup commit (5aa177d1), not a previous bug fix — this change does not revert any historical fix.
  • Only one caller (keyPressEvent) invokes displayShortcuts() (confirmed via gitnexus impact); no other shortcut branches or callers are affected.
  • isAutoRepeat() is a standard Qt API since Qt4; no version compatibility risk.

Business Impact Scope

The change affects only the Ctrl+Shift+? shortcut preview feature in deepin-editor. When the user holds the key combination, the shortcut preview window (deepin-shortcut-viewer) will now stay visible instead of flashing and disappearing. All other keyboard shortcuts are unaffected. Releasing and re-pressing the key combination still reopens the preview.

Verification Suggestion

  1. Hold Ctrl+Shift+? in deepin-editor — verify the shortcut preview stays visible.
  2. Release and re-press Ctrl+Shift+? — verify the preview reopens.
  3. Test other shortcuts (e.g., Ctrl+S, Ctrl+O) — verify no regression.

根因分析

Window::keyPressEvent 的 displayshortcuts 快捷键分支在调用 displayShortcuts() 时未检查 QKeyEvent::isAutoRepeat()。用户按住 Ctrl+Shift+? 时 Qt 以约 10–30 次/秒产生 auto-repeat KeyPress 事件,每次都触发 displayShortcuts(),后者每次都通过 QProcess::startDetached("deepin-shortcut-viewer") 启动新的预览进程。多个预览实例竞争窗口焦点,后启动的实例使前一个失去焦点而关闭,表现为预览界面"一闪而过"(证据:window.cpp:4587–4589、window.cpp:2691–2692)。

修复方案

在 keyPressEvent 的 displayshortcuts 分支、调用 displayShortcuts() 前增加 isAutoRepeat() 守卫,auto-repeat 事件直接 return,仅首次按键触发预览。与分析报告第十节方案一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行(4587–4592)最后由样式整理提交(5aa177d1)引入,非历史 bug 修复产物,本次改动不会撤销历史修复。
  • displayShortcuts() 仅 keyPressEvent 一处调用(gitnexus impact 确认),不影响其他快捷键分支。
  • isAutoRepeat() 为 Qt4+ 标准 API,无版本兼容风险。

业务影响范围

改动仅影响 deepin-editor 的 Ctrl+Shift+? 快捷键预览功能。用户按住该组合键时,快捷键预览界面(deepin-shortcut-viewer)将持续显示而非一闪而过。其他快捷键不受影响。释放后再次按下仍可重新打开预览。

验证建议

  1. 在 deepin-editor 中按住 Ctrl+Shift+?,验证快捷键预览界面持续显示。
  2. 释放后再次按下 Ctrl+Shift+?,验证可重新打开预览。
  3. 测试其他快捷键(如 Ctrl+S、Ctrl+O),验证无回归。

Summary by Sourcery

Bug Fixes:

  • Prevent repeated key events from repeatedly launching the shortcut viewer, keeping the preview visible when Ctrl+Shift+? is held.

1. Root cause: keyPressEvent did not filter auto-repeat events for the
   displayshortcuts shortcut, each repeat launched a new
   deepin-shortcut-viewer process that killed the previous one
2. Fix: add isAutoRepeat() early-return guard before calling
   displayShortcuts() so only the initial key press triggers it
3. Impact: only the displayshortcuts branch is affected, no change to
   other shortcuts or to displayShortcuts() itself

Log: 修复快捷键预览界面一闪而过的问题

Influence:
1. Test Ctrl+Shift+? shortcut preview stays visible while holding
2. Test releasing and re-pressing Ctrl+Shift+? reopens preview
3. Verify other shortcuts are unaffected

fix: 修复快捷键预览界面一闪而过无法持续显示

1. 根因:keyPressEvent 未过滤 auto-repeat 事件,按住 Ctrl+Shift+? 时
   每次 auto-repeat 都启动新的 deepin-shortcut-viewer 进程,新进程
   杀掉旧进程导致预览界面一闪而过
2. 方案:在调用 displayShortcuts() 前添加 isAutoRepeat() 守卫,仅
   首次按键触发,auto-repeat 事件直接返回
3. 影响:仅影响 displayshortcuts 分支,不改变其他快捷键行为,不
   改变 displayShortcuts() 函数本身

Log: 修复快捷键预览界面一闪而过的问题

Influence:
1. 测试按住 Ctrl+Shift+? 时预览界面持续显示
2. 测试释放后再次按下 Ctrl+Shift+? 可重新打开预览
3. 验证其他快捷键功能不受影响

PMS: BUG-381385
@add-uos
add-uos marked this pull request as draft November 20, 2026 13:22
@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Ignore auto-repeat key events in the displayshortcuts branch so holding the shortcut launches the preview only once.

  • src/widgets/window.cpp L4588-4589

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

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