Skip to content

fix(reader): restore arrow key scrolling by removing QAction shortcut registration - #407

Open
Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:agent/pms-bug-bot/05ace414d55b
Open

Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:agent/pms-bug-bot/05ace414d55b

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Sep 24, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

Arrow keys (Left/Right/Up/Down) and Space were registered as QAction shortcuts in Central.cpp's constructor. Qt's QAction shortcut mechanism intercepts these key events before they reach SheetBrowser's keyPressEvent() default scroll handling. Meanwhile, the page navigation logic for left/right keys in CentralDocPage.cpp:664-667 was already commented out, so the QAction trigger had no effect — it only blocked the default scrolling behavior.

This is a regression: commit a81e5e19 previously fixed this exact issue (PMS 134413) by commenting out the QAction registrations, but merge commit b20fcf92 (v23 code merge) reverted the fix.

Fix

Comment out the QAction shortcut registrations for Qt::Key_Left, Qt::Key_Right, Qt::Key_Up, Qt::Key_Down, and Qt::Key_Space in Central.cpp. Remove the m_slideWidget->handleKeyPressEvent(s) forwarding call in CentralDocPage.cpp since keys no longer route through QAction. Add a keyPressEvent() override and setFocus() in SlideWidget constructor so slide show mode handles arrow keys and space independently via its own handleKeyPressEvent().

This restores the fix from commit a81e5e19 that was reverted by the v23 merge.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The change comments out QAction registrations and adds a keyPressEvent override to SlideWidget — no function signatures changed, no external callers affected.
  • Historical commit a81e5e19 applied the identical fix successfully; this change re-applies it after it was reverted by merge b20fcf92.

Business Impact Scope

  • Document reading (normal mode): Arrow keys and Space restore Qt default scrolling behavior — fixes the reported bug.
  • Slide show mode: Arrow keys (prev/next page) and Space (play/pause) handled by SlideWidget::keyPressEvent() independently — no behavior change.

Verification Suggestion

  • Normal reading mode: press Up/Down/Left/Right to verify page scrolling works.
  • Slide show mode: press Left/Right to navigate pages, Space to toggle auto-play, Esc to exit.

根因分析

Central.cpp 构造函数中将 Qt::Key_Left/Key_Right/Key_Up/Key_Down/Key_Space 注册为 QAction 快捷键,Qt 快捷键机制在事件到达 SheetBrowser 的 keyPressEvent() 默认滚动处理之前拦截了这些按键。同时 CentralDocPage.cpp:664-667 中的左右键切页逻辑已被注释,QAction 触发后无任何动作,仅阻止了默认滚动行为。

此为回归问题:commit a81e5e19 曾修复过相同问题(PMS 134413),合并 commit b20fcf92(v23 代码合并)回退了该修复。

修复方案

注释 Central.cpp 中 5 个方向键/空格的 QAction 快捷键注册;移除 CentralDocPage.cpp 中 m_slideWidget->handleKeyPressEvent(s) 转发调用;在 SlideWidget 构造函数中添加 setFocus(),新增 keyPressEvent() 覆写,使幻灯片模式通过自身接收键盘事件。

恢复历史 commit a81e5e19 的修复方案(被 v23 合并 commit b20fcf92 回退)。

改动安全评估

代码安全

  • 风险等级:低
  • 改动仅注释 QAction 注册行 + 为 SlideWidget 新增 keyPressEvent 覆写,不涉及函数签名变更,无外部调用者受影响。
  • 历史 commit a81e5e19 曾以相同方式修复成功,本次为重新应用被回退的修复。

业务影响范围

  • 文档阅读(普通模式):方向键/空格恢复 Qt 默认滚动行为,修复 PMS 374547 报告的方向键无法滚动问题。
  • 幻灯片模式:方向键翻页、空格播放/暂停由 SlideWidget::keyPressEvent() 自行处理,功能不变。

验证建议

  • 普通阅读模式:按上/下/左/右方向键验证页面滚动。
  • 幻灯片模式:按左/右方向键翻页、空格播放/暂停、ESC 退出。

Summary by Sourcery

Restore normal reading keyboard scrolling while preserving independent keyboard controls for slide-show mode.

Bug Fixes:

  • Restore arrow-key and Space scrolling in normal document reading by removing conflicting QAction shortcut registrations.

Enhancements:

  • Make slide-show keyboard handling independent by routing key events directly to SlideWidget and ensuring it receives focus.

Tests:

  • Update CentralDocPage and SlideWidget unit tests to validate direct key-event handling and the revised shortcut flow.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Resurgamz

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 Sep 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Restores normal reading-mode scrolling by removing QAction registrations that intercepted arrow keys and Space, while preserving slide-show keyboard behavior through direct focus and a keyPressEvent override.

Sequence diagram for restored keyboard scrolling and slide-show handling

sequenceDiagram
    actor User
    participant SheetBrowser
    participant SlideWidget
    participant Utils

    User->>SheetBrowser: keyPressEvent(event)
    Note over SheetBrowser: Arrow keys and Space are no longer QAction shortcuts
    SheetBrowser-->>User: Default scrolling behavior

    User->>SlideWidget: keyPressEvent(event)
    SlideWidget->>Utils: getKeyshortcut(event)
    Utils-->>SlideWidget: key
    SlideWidget->>SlideWidget: handleKeyPressEvent(key)
    SlideWidget-->>User: Navigate slides or toggle autoplay
Loading

Flow diagram for keyboard event routing after shortcut removal

flowchart TD
    A[Keyboard input] --> B{Slide-show mode?}
    B -- No --> C[SheetBrowser keyPressEvent]
    C --> D[Qt default scrolling]
    B -- Yes --> E[SlideWidget receives focus]
    E --> F[SlideWidget keyPressEvent]
    F --> G[Utils.getKeyshortcut]
    G --> H[SlideWidget.handleKeyPressEvent]
    H --> I[Slide navigation or autoplay control]
Loading

File-Level Changes

Change Details Files
Remove global QAction interception so normal document views receive navigation keys through Qt's default scrolling path.
  • Disable Left, Right, Up, Down, and Space shortcut registrations.
  • Stop forwarding shortcut strings to the slide widget from document-page shortcut handling.
reader/uiframe/Central.cpp
reader/uiframe/CentralDocPage.cpp
Give slide show mode direct keyboard focus and event handling for navigation and playback controls.
  • Schedule focus assignment after the slide widget is shown.
  • Translate key events with the shared shortcut utility and dispatch them through the existing slide handler before default widget processing.
reader/widgets/SlideWidget.cpp
reader/widgets/SlideWidget.h

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


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

… registration

Arrow keys (Left/Right/Up/Down) and Space were registered as QAction
shortcuts in Central.cpp constructor, which intercepted key events and
prevented Qt's default scrolling behavior in document reading mode.
The page navigation logic in CentralDocPage.cpp for these keys was
already commented out, so the QAction had no effect except blocking
default scrolling.

Fix by commenting out the QAction registrations for these keys in
Central.cpp, removing the slide widget key forwarding in
CentralDocPage.cpp, and adding a keyPressEvent override to SlideWidget
with setFocus() in its constructor so slide show mode handles arrow
keys and space independently. This restores the fix from commit
a81e5e1 that was reverted by the v23 merge commit b20fcf9.

Log: 方向键无法滚动文档页面
Bug: https://pms.uniontech.com/bug-view-374547.html
@Resurgamz
Resurgamz force-pushed the agent/pms-bug-bot/05ace414d55b branch from e5f17ee to 875dac1 Compare September 24, 2026 08:36
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值,代码质量符合要求。本次变更通过移除 QAction 快捷键注册恢复箭头键滚动功能,实现方案合理,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰,无需修改。建议确认 Utils::getKeyshortcut 函数对所有可能的 QKeyEvent 均能返回有效字符串,避免 handleKeyPressEvent 接收到空字符串。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. reader/widgets/SlideWidget.cpp:350 - 新增 keyPressEvent 方法缺少注释说明设计意图
  2. reader/uiframe/Central.cpp:48 - 注释掉的代码属于死代码,建议直接删除而非注释保留

建议: 1.建议将注释掉的快捷键注册代码直接删除,依赖版本控制历史保留记录,避免死代码积累 2.建议为 keyPressEvent 方法添加简要注释说明为何需要重载此方法(如'通过 Qt 事件系统直接处理按键,绕过 QAction 快捷键拦截')


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理,无需优化。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无安全风险。本次变更仅涉及键盘事件处理逻辑调整,不涉及用户输入校验、文件操作、网络通信或权限控制等安全敏感场景。


💡 改进建议代码示例

// 建议删除注释掉的代码,而非保留
// Central.cpp 中直接移除以下注释行:
// keyList.append(QKeySequence(Qt::Key_Left));
// keyList.append(QKeySequence(Qt::Key_Right));
// ...

// 建议为 keyPressEvent 添加注释
/**
 * @brief 重载按键事件处理
 * 通过 Qt 事件系统直接处理按键,绕过 QAction 快捷键拦截
 * @param event 按键事件
 */
void SlideWidget::keyPressEvent(QKeyEvent *event)
{
    QString key = Utils::getKeyshortcut(event);
    handleKeyPressEvent(key);
    DWidget::keyPressEvent(event);
}

本报告由 AI 代码审查工具自动生成

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