fix: allow right-click long press to trigger context menu on touchscreen#755
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAllows long-press context menus to be triggered by both touch (no button) and right mouse button across icon and app list delegates, by relaxing the onPressAndHold button check in relevant QML views. Sequence diagram for long press context menu triggering with touch and right-clicksequenceDiagram
actor User
participant InputDevice
participant QMLDelegate
participant ContextMenu
User->>InputDevice: LongPressOnIcon
InputDevice->>QMLDelegate: onPressAndHold(mouse)
alt Touchscreen_long_press
Note right of InputDevice: mouse.button = Qt.NoButton
QMLDelegate->>QMLDelegate: checkButton(mouse.button)
QMLDelegate->>ContextMenu: open()
else Right_click_long_press
Note right of InputDevice: mouse.button = Qt.RightButton
QMLDelegate->>QMLDelegate: checkButton(mouse.button)
QMLDelegate->>ContextMenu: open()
else Other_buttons
QMLDelegate->>QMLDelegate: ignore event
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
IconItemDelegate.qmlthe updated condition uses|||instead of||, which will cause a syntax error and needs to be corrected. - Since the same
mouse.button === Qt.NoButton || mouse.button === Qt.RightButtoncondition is now repeated across several QML files, consider extracting this into a shared helper or function to keep the behavior consistent and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `IconItemDelegate.qml` the updated condition uses `|||` instead of `||`, which will cause a syntax error and needs to be corrected.
- Since the same `mouse.button === Qt.NoButton || mouse.button === Qt.RightButton` condition is now repeated across several QML files, consider extracting this into a shared helper or function to keep the behavior consistent and easier to maintain.
## Individual Comments
### Comment 1
<location path="qml/IconItemDelegate.qml" line_range="161" />
<code_context>
// touchscreen long press.
onPressAndHold: function (mouse) {
- if (mouse.button === Qt.NoButton) {
+ if (mouse.button === Qt.NoButton ||| mouse.button === Qt.RightButton) {
root.menuTriggered()
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Fix the `|||` operator, which is invalid JavaScript/QML syntax.
Use `||` here (as in the other handlers) so the condition parses correctly and matches the intended `NoButton` or `RightButton` behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
reliability Replaced the `onPressAndHold` event handler with a `TapHandler` component for touchscreen long press interactions across multiple QML files. This change prevents duplicate handling of touch events by introducing a flag `isTouchLongPressed` that blocks the subsequent `onClicked` execution. The old `onPressAndHold` approach was unreliable and caused duplicated menu triggers. Log: Improved touchscreen long press reliability by using TapHandler Influence: 1. Test touchscreen long press on icon items to trigger context menu 2. Verify that short tap still properly triggers the default action (e.g., launching app) 3. Ensure no duplicate menu popups occur during touch interaction 4. Test with mouse input to confirm no regression in right-click context menu 5. Verify drag-and-drop behavior remains unaffected on touch devices fix: 使用 TapHandler 替代触摸长按处理以提高可靠性 将多个 QML 文件中的 `onPressAndHold` 事件处理器替换为 `TapHandler` 组件 来处理触摸屏长按交互。此修改通过引入 `isTouchLongPressed` 标志位来阻止后 续的 `onClicked` 重复执行,解决了原有 `onPressAndHold` 方法不可靠导致的 菜单重复触发问题。 Log: 通过使用 TapHandler 提高触摸长按的可靠性 Influence: 1. 测试触摸屏长按图标项是否正常触发上下文菜单 2. 验证短触是否仍能正常触发默认操作(如启动应用) 3. 确保触摸交互期间不会出现重复的菜单弹窗 4. 测试鼠标输入,确认右键上下文菜单无回归问题 5. 验证触摸设备上的拖拽功能不受影响 PMS: BUG-358827
deepin pr auto review这段代码主要是对QML中触摸屏长按(Long Press)和鼠标点击(Click)事件的交互逻辑进行了重构。它将原来使用 MouseArea 的 以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 改进建议
总结这段代码的修改是积极且有效的。它通过引入 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: behind) |
Log: Fixed context menu not opening on right-click long press
Influence:
fix: 允许右键长按触发上下文菜单
Log: 修复右键长按时上下文菜单无法打开的问题
Influence:
PMS: BUG-358827
Summary by Sourcery
Bug Fixes: