Skip to content

Commit 5999810

Browse files
committed
fix: prevent focus issues during mouse wheel page navigation
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 parent b178a28 commit 5999810

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

qml/FolderGridViewPopup.qml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -174,6 +174,13 @@ Popup {
174174
Layout.fillHeight: true
175175
color: "transparent"
176176

177+
// 用于鼠标滚轮滚动时接收焦点,使 GridView 失去 activeFocus
178+
Item {
179+
id: wheelFocusSink
180+
width: 0
181+
height: 0
182+
}
183+
177184
DropArea {
178185
id: folderPageDropArea
179186
property int pageIntent: 0
@@ -255,6 +262,8 @@ Popup {
255262

256263
// TODO: this might not be the correct way to handle wheel
257264
onWheel: function (wheel) {
265+
// 鼠标滚轮翻页时将焦点转移到 wheelFocusSink,使 GridView 失去 activeFocus
266+
wheelFocusSink.forceActiveFocus()
258267
let xDelta = wheel.angleDelta.x / 8
259268
let yDelta = wheel.angleDelta.y / 8
260269
let toPage = 0; // -1 prev, +1 next, 0 don't change
@@ -281,11 +290,15 @@ Popup {
281290
activeFocusOnTab: false
282291
//达到起始和末尾应用按下左右键时进行标志,-1往左翻页(标志前一页的最后一个应用),0代表往右翻页(标志后一页的第一个应用)
283292
property int pendingFocusIndex: 0
284-
//这里不能使用onCurrentIndexChanged
293+
// 标记翻页是否由键盘操作触发,鼠标滚轮翻页时不应设置选中焦点
294+
property bool pageChangedByKeyboard: false
295+
//这里不能使用onCurrentIndexChanged
285296
//由于如果目标页的 Loader/GridViewContainer 还没加载完成,这次设置焦点会被跳过 则默认焦点给到的页面本身而不是应用
286297
onCurrentItemChanged: {
287-
if (currentItem)
298+
if (currentItem && pageChangedByKeyboard) {
288299
currentItem.resetCurrentIndex(pendingFocusIndex)
300+
pageChangedByKeyboard = false
301+
}
289302
}
290303

291304
Connections {
@@ -417,6 +430,7 @@ Popup {
417430
}
418431

419432
folderPagesView.pendingFocusIndex = -1
433+
folderPagesView.pageChangedByKeyboard = true
420434
if (folderPagesView.currentIndex === 0) {
421435
folderPagesView.setCurrentIndex(pageCount - 1)
422436
} else {
@@ -444,6 +458,7 @@ Popup {
444458
}
445459

446460
folderPagesView.pendingFocusIndex = 0
461+
folderPagesView.pageChangedByKeyboard = true
447462
if (folderPagesView.currentIndex === (pageCount - 1)) {
448463
folderPagesView.setCurrentIndex(0)
449464
} else {
@@ -500,6 +515,7 @@ Popup {
500515
}
501516

502517
folderPagesView.pendingFocusIndex = -1
518+
folderPagesView.pageChangedByKeyboard = true
503519
if (folderPagesView.currentIndex === 0) {
504520
folderPagesView.setCurrentIndex(pageCount - 1)
505521
} else {
@@ -527,6 +543,7 @@ Popup {
527543
}
528544

529545
folderPagesView.pendingFocusIndex = 0
546+
folderPagesView.pageChangedByKeyboard = true
530547
if (folderPagesView.currentIndex === (pageCount - 1)) {
531548
folderPagesView.setCurrentIndex(0)
532549
} else {

0 commit comments

Comments
 (0)