Skip to content

fix: prevent focus issues during mouse wheel page navigation#713

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-343143
Feb 27, 2026
Merged

fix: prevent focus issues during mouse wheel page navigation#713
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-343143

Conversation

@wjyrich

@wjyrich wjyrich commented Feb 27, 2026

Copy link
Copy Markdown
Contributor
  1. Added wheelFocusSink Item to capture focus during mouse wheel scrolling
  2. Introduced pageChangedByKeyboard property to distinguish between keyboard and mouse wheel page changes
  3. Modified onWheel handler to transfer focus to wheelFocusSink before page navigation
  4. Updated currentItemChanged handler to only reset focus when page change was triggered by keyboard
  5. Ensured pageChangedByKeyboard is set to true for all keyboard navigation scenarios

Log: Fixed focus behavior when using mouse wheel to navigate between folder pages

Influence:

  1. Test mouse wheel scrolling between folder pages - focus should not jump to applications
  2. Verify keyboard navigation (arrow keys, Tab) still correctly focuses applications
  3. Test mixed usage of mouse wheel and keyboard navigation
  4. Verify focus behavior when switching pages with both input methods
  5. Test edge cases like single page folders and multi-page navigation

fix: 修复鼠标滚轮翻页时的焦点问题

  1. 添加 wheelFocusSink Item 用于在鼠标滚轮滚动时捕获焦点
  2. 引入 pageChangedByKeyboard 属性区分键盘和鼠标滚轮触发的翻页
  3. 修改 onWheel 处理程序,在页面导航前将焦点转移到 wheelFocusSink
  4. 更新 currentItemChanged 处理程序,仅在键盘触发翻页时重置焦点
  5. 确保所有键盘导航场景都将 pageChangedByKeyboard 设置为 true

Log: 修复使用鼠标滚轮在文件夹页面间导航时的焦点行为

Influence:

  1. 测试鼠标滚轮在文件夹页面间滚动 - 焦点不应跳转到应用程序
  2. 验证键盘导航(方向键、Tab键)仍能正确聚焦应用程序
  3. 测试混合使用鼠标滚轮和键盘导航的情况
  4. 验证使用两种输入方法切换页面时的焦点行为
  5. 测试边缘情况,如单页文件夹和多页导航

PMS: BUG-343143

1. Added wheelFocusSink Item to capture focus during mouse wheel
scrolling
2. Introduced pageChangedByKeyboard property to distinguish between
keyboard and mouse wheel page changes
3. Modified onWheel handler to transfer focus to wheelFocusSink before
page navigation
4. Updated currentItemChanged handler to only reset focus when page
change was triggered by keyboard
5. Ensured pageChangedByKeyboard is set to true for all keyboard
navigation scenarios

Log: Fixed focus behavior when using mouse wheel to navigate between
folder pages

Influence:
1. Test mouse wheel scrolling between folder pages - focus should not
jump to applications
2. Verify keyboard navigation (arrow keys, Tab) still correctly focuses
applications
3. Test mixed usage of mouse wheel and keyboard navigation
4. Verify focus behavior when switching pages with both input methods
5. Test edge cases like single page folders and multi-page navigation

fix: 修复鼠标滚轮翻页时的焦点问题

1. 添加 wheelFocusSink Item 用于在鼠标滚轮滚动时捕获焦点
2. 引入 pageChangedByKeyboard 属性区分键盘和鼠标滚轮触发的翻页
3. 修改 onWheel 处理程序,在页面导航前将焦点转移到 wheelFocusSink
4. 更新 currentItemChanged 处理程序,仅在键盘触发翻页时重置焦点
5. 确保所有键盘导航场景都将 pageChangedByKeyboard 设置为 true

Log: 修复使用鼠标滚轮在文件夹页面间导航时的焦点行为

Influence:
1. 测试鼠标滚轮在文件夹页面间滚动 - 焦点不应跳转到应用程序
2. 验证键盘导航(方向键、Tab键)仍能正确聚焦应用程序
3. 测试混合使用鼠标滚轮和键盘导航的情况
4. 验证使用两种输入方法切换页面时的焦点行为
5. 测试边缘情况,如单页文件夹和多页导航

PMS: BUG-343143

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

Sorry @wjyrich, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

Git Diff 代码审查

总体评估

这段代码主要修改了 FolderGridViewPopup.qml 文件,用于改进文件夹网格视图中的焦点管理逻辑,特别是在处理鼠标滚轮翻页和键盘导航时的焦点行为。代码总体逻辑清晰,但存在一些可以改进的地方。

代码审查意见

1. 语法逻辑

  • 优点:代码逻辑清晰,通过添加 wheelFocusSinkpageChangedByKeyboard 属性来区分鼠标滚轮和键盘操作导致的页面切换
  • 问题
    • wheelFocusSinkwidthheight 都设置为 0,这可能导致某些情况下焦点接收不可靠。建议至少设置为 1x1 像素
    • onWheel 事件中,先调用 wheelFocusSink.forceActiveFocus() 然后计算滚轮事件,这可能导致滚轮事件处理不一致

2. 代码质量

  • 优点
    • 添加了清晰的注释说明代码意图
    • 使用了有意义的变量名
  • 问题
    • 代码中有多处重复的焦点设置逻辑,可以提取为函数减少重复
    • 注释中提到 "这里不能使用onCurrentIndexChanged",但没有解释原因,建议补充说明

3. 代码性能

  • 问题
    • 每次滚轮事件都调用 forceActiveFocus() 可能会导致不必要的焦点切换,即使不需要翻页
    • wheelFocusSink 作为始终存在的 Item,可能会增加不必要的对象开销

4. 代码安全

  • 问题
    • 没有对 wheel.angleDelta 进行边界检查,如果传入异常值可能导致计算错误
    • 没有对 pendingFocusIndex 的有效性进行验证

改进建议

  1. 修改 wheelFocusSink 的尺寸:
Item {
    id: wheelFocusSink
    width: 1  // 至少设置为1像素确保焦点接收
    height: 1
    visible: false  // 设置为不可见但保持可聚焦
}
  1. 优化滚轮事件处理逻辑:
onWheel: function (wheel) {
    let xDelta = wheel.angleDelta.x / 8
    let yDelta = wheel.angleDelta.y / 8
    let toPage = 0; // -1 prev, +1 next, 0 don't change
    
    // 添加边界检查
    if (Math.abs(xDelta) > 120 || Math.abs(yDelta) > 120) {
        // 确认需要翻页后再转移焦点
        wheelFocusSink.forceActiveFocus()
        // ... 其余翻页逻辑
    }
}
  1. 提取重复的焦点设置逻辑:
function navigateToPage(direction, focusIndex) {
    folderPagesView.pendingFocusIndex = focusIndex
    folderPagesView.pageChangedByKeyboard = true
    
    if (direction === -1) {
        if (folderPagesView.currentIndex === 0) {
            folderPagesView.setCurrentIndex(pageCount - 1)
        } else {
            folderPagesView.decrementCurrentIndex()
        }
    } else {
        if (folderPagesView.currentIndex === (pageCount - 1)) {
            folderPagesView.setCurrentIndex(0)
        } else {
            folderPagesView.incrementCurrentIndex()
        }
    }
}
  1. 添加更详细的注释说明为什么不能使用 onCurrentIndexChanged
// 这里不能使用onCurrentIndexChanged
// 原因:如果目标页的 Loader/GridViewContainer 还没加载完成,
// 这次设置焦点会被跳过,则默认焦点给到的页面本身而不是应用
  1. 考虑添加对 pendingFocusIndex 的有效性验证:
onCurrentItemChanged: {
    if (currentItem && pageChangedByKeyboard) {
        // 验证 pendingFocusIndex 在有效范围内
        if (pendingFocusIndex >= -1 && pendingFocusIndex < itemCount) {
            currentItem.resetCurrentIndex(pendingFocusIndex)
        }
        pageChangedByKeyboard = false
    }
}

总结

这段代码改进了文件夹网格视图中的焦点管理逻辑,特别是在处理鼠标滚轮翻页和键盘导航时的焦点行为。虽然代码整体逻辑清晰,但可以通过上述建议进一步优化代码质量、性能和安全性。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, wjyrich

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

@wjyrich

wjyrich commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Feb 27, 2026

Copy link
Copy Markdown

This pr force merged! (status: behind)

@deepin-bot deepin-bot Bot merged commit 6455cbe into linuxdeepin:master Feb 27, 2026
10 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