fix: prevent focus issues during mouse wheel page navigation#713
Merged
Conversation
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
deepin pr auto reviewGit Diff 代码审查总体评估这段代码主要修改了 代码审查意见1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议
Item {
id: wheelFocusSink
width: 1 // 至少设置为1像素确保焦点接收
height: 1
visible: false // 设置为不可见但保持可聚焦
}
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()
// ... 其余翻页逻辑
}
}
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()
}
}
}
// 这里不能使用onCurrentIndexChanged
// 原因:如果目标页的 Loader/GridViewContainer 还没加载完成,
// 这次设置焦点会被跳过,则默认焦点给到的页面本身而不是应用
onCurrentItemChanged: {
if (currentItem && pageChangedByKeyboard) {
// 验证 pendingFocusIndex 在有效范围内
if (pendingFocusIndex >= -1 && pendingFocusIndex < itemCount) {
currentItem.resetCurrentIndex(pendingFocusIndex)
}
pageChangedByKeyboard = false
}
}总结这段代码改进了文件夹网格视图中的焦点管理逻辑,特别是在处理鼠标滚轮翻页和键盘导航时的焦点行为。虽然代码整体逻辑清晰,但可以通过上述建议进一步优化代码质量、性能和安全性。 |
BLumia
approved these changes
Feb 27, 2026
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
|
This pr force merged! (status: behind) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log: Fixed focus behavior when using mouse wheel to navigate between folder pages
Influence:
fix: 修复鼠标滚轮翻页时的焦点问题
Log: 修复使用鼠标滚轮在文件夹页面间导航时的焦点行为
Influence:
PMS: BUG-343143