Skip to content

fix(keyboard): SheetSidebar::event() 不再处理 Alt+M 消除双菜单#286

Open
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:master
Open

fix(keyboard): SheetSidebar::event() 不再处理 Alt+M 消除双菜单#286
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

log:

  • Application::notify() 早已把 Alt+M 转为模拟 RightButton MouseEvent 发给焦点 widget,由 SideBarImageListView::mousePressEvent 右键分支 弹菜单;SheetSidebar::event() 同时再调一次 showMenu() 导致双菜单 (一在鼠标位置、一在 visualRect 位置),需按两次 ESC 才能关闭
  • 删除 event() 中 Alt+M (Qt::Key_M + AltModifier) 判断,仅保留 Key_Menu (键盘菜单键) 处理路径;Alt+M 完全由 Application::notify 独占,与右键单击行为一致,一次 ESC 即可关闭

pms: bug-363119

Summary by Sourcery

Bug Fixes:

  • Stop handling Alt+M in SheetSidebar to avoid triggering duplicate context menus that require multiple ESC presses to dismiss.

log:
- Application::notify() 早已把 Alt+M 转为模拟 RightButton MouseEvent
  发给焦点 widget,由 SideBarImageListView::mousePressEvent 右键分支
  弹菜单;SheetSidebar::event() 同时再调一次 showMenu() 导致双菜单
  (一在鼠标位置、一在 visualRect 位置),需按两次 ESC 才能关闭
- 删除 event() 中 Alt+M (Qt::Key_M + AltModifier) 判断,仅保留
  Key_Menu (键盘菜单键) 处理路径;Alt+M 完全由 Application::notify
  独占,与右键单击行为一致,一次 ESC 即可关闭

pms: bug-363119
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

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

Reviewer's Guide

SheetSidebar::event() is simplified to only handle the keyboard Menu key (Qt::Key_Menu) and no longer treats Alt+M as a menu trigger, avoiding duplicate context menus because Alt+M is already converted to a right-click by Application::notify().

Sequence diagram for updated keyboard menu handling

sequenceDiagram
    participant User
    participant Application
    participant SheetSidebar
    participant SideBarImageListView
    participant ContextMenu

    %% Alt+M path (handled only by Application::notify)
    User->>Application: notify(KeyPress Alt+M)
    Application->>Application: notify
    Application->>SideBarImageListView: MouseEvent RightButton
    SideBarImageListView->>SideBarImageListView: mousePressEvent
    SideBarImageListView->>ContextMenu: showMenu

    %% Keyboard Menu key path (handled by SheetSidebar::event)
    User->>SheetSidebar: event(QEvent::KeyPress Key_Menu)
    SheetSidebar->>SheetSidebar: event
    SheetSidebar->>ContextMenu: showMenu
Loading

File-Level Changes

Change Details Files
Limit SheetSidebar keyboard handling to the Menu key and stop consuming Alt+M so it behaves like a normal right-click handled upstream.
  • Remove Alt+M (Qt::Key_M with AltModifier) detection and handling inside SheetSidebar::event().
  • Keep handling for Qt::Key_Menu when the key event is not an auto-repeat and call showMenu() in that case.
  • Allow Alt+M to be processed solely by Application::notify(), aligning its behavior with a standard right mouse button click and preventing double menus.
reader/sidebar/SheetSidebar.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:

  • Now that Alt+M is handled exclusively in Application::notify, consider keeping a brief comment here explaining why Key_Menu events are still consumed (to avoid Qt mnemonic/accelerator side effects), so future readers don’t reintroduce Alt+M handling or remove the consumption logic by mistake.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that Alt+M is handled exclusively in Application::notify, consider keeping a brief comment here explaining why Key_Menu events are still consumed (to avoid Qt mnemonic/accelerator side effects), so future readers don’t reintroduce Alt+M handling or remove the consumption logic by mistake.

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.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码通过移除冲突的快捷键逻辑精准修复了UI弹窗异常问题,实现简洁有效
逻辑完全正确且无任何安全漏洞,得满分

■ 【详细分析】

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

修改后的代码在 SheetSidebar::event 函数中直接判断按键是否为 Qt::Key_Menu 并通过 isAutoRepeat() 排除按键重复事件,语法与逻辑均无误
建议:无需改进

  • 2.代码质量(良好)✓

移除了冗余的中间布尔变量 isMenuKey 和 isAltM,使条件判断更加直观,消除了之前为了规避 Qt 机制而添加的冗长注释,代码更加清爽
建议:若产品需求文档中明确要求必须支持 Alt+M 快捷键,建议在后续版本中通过重写 keyReleaseEvent 或使用 QShortcut 规范处理,而非直接删除该功能

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

减少了局部布尔变量的内存分配与额外的位运算判断,事件分发处理性能有极微小提升
建议:无需改进

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
该修改仅涉及UI层键盘事件的过滤与拦截,不涉及内存操作、外部命令执行、敏感数据解析或权限变更,无任何安全风险

  • 建议:保持现有的安全编码水平

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需额外修改,以下为保持当前逻辑的完整上下文参考实现
bool SheetSidebar::event(QEvent *event)
{
    if (event->type() == QEvent::KeyPress) {
        QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
        if (key_event->key() == Qt::Key_Menu && !key_event->isAutoRepeat()) {
            showMenu();
            return true;
        }
    }
    return QWidget::event(event);
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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