Skip to content

Commit 1db4b47

Browse files
committed
fix: improve focus handling after expand/collapse in NotifyView
Added retry timer mechanism to reliably set focus after expand/collapse operations. Log: improve focus handling after expand/collapse in NotifyView pms: BUG-339891
1 parent 43298e3 commit 1db4b47

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

panels/notification/center/NotifyView.qml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,41 @@ Control {
6161
activeFocusOnTab: false
6262
ScrollBar.vertical: ScrollBar { }
6363
property int nextIndex: -1
64+
property int pendingFocusIndex: -1 // Index to focus after expand operation
6465
property bool panelShown: false
6566

6667
// Forward signals from delegate to root for Tab cycling
6768
function gotoHeaderFirst() { root.gotoHeaderFirst() }
6869
function gotoHeaderLast() { root.gotoHeaderLast() }
6970

71+
// Request focus on item after expand with retry
72+
function requestFocusOnExpand(idx) {
73+
pendingFocusIndex = idx
74+
currentIndex = idx
75+
positionViewAtIndex(idx, ListView.Contain)
76+
expandFocusTimer.retries = 15
77+
expandFocusTimer.start()
78+
}
79+
80+
Timer {
81+
id: expandFocusTimer
82+
property int retries: 15
83+
interval: 50
84+
repeat: true
85+
onTriggered: {
86+
let item = view.itemAtIndex(view.pendingFocusIndex)
87+
if (item && item.enabled) {
88+
item.forceActiveFocus()
89+
view.pendingFocusIndex = -1
90+
stop()
91+
} else if (retries <= 0) {
92+
view.pendingFocusIndex = -1
93+
stop()
94+
}
95+
retries--
96+
}
97+
}
98+
7099
onNextIndexChanged: {
71100
if (nextIndex >= 0 && count > 0) {
72101
currentIndex = nextIndex

panels/notification/center/NotifyViewDelegate.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ DelegateChooser {
8080

8181
onCollapse: function () {
8282
console.log("collapse group", model.appName)
83+
let collapseIndex = index
8384
notifyModel.collapseApp(index)
85+
root.view.requestFocusOnExpand(collapseIndex)
8486
}
8587

8688
onSetting: function (pos) {
@@ -259,7 +261,7 @@ DelegateChooser {
259261
console.log("expand")
260262
let expandIndex = model.index
261263
notifyModel.expandApp(expandIndex)
262-
root.view.nextIndex = expandIndex + 1
264+
root.view.requestFocusOnExpand(expandIndex + 1)
263265
}
264266
onSetting: function (pos) {
265267
let tmp = mapToItem(root.view, pos)

0 commit comments

Comments
 (0)