Skip to content

Commit

Permalink
fix: highlight not visible when focus in
Browse files Browse the repository at this point in the history
Always scroll to the highlight when focus in.

Log: fix highlight not visible when focus in
Issue: linuxdeepin/developer-center#6397
  • Loading branch information
asterwyx committed Jan 5, 2024
1 parent 8fb6213 commit a14c9bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
12 changes: 10 additions & 2 deletions qml/AppListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Item {
// the scroll might stopped before the highlight item scroll to the expected place.
// Thus we use a timer to set back these values with a delay.
listView.highlightMoveDuration = 150
listView.highlightRangeMode = GridView.NoHighlightRange
listView.highlightRangeMode = ListView.NoHighlightRange
}
}

Expand All @@ -34,7 +34,7 @@ Item {
if (character === transliterated1st) {
// we use the highlight move to scroll to item
listView.highlightMoveDuration = 0
listView.highlightRangeMode = GridView.ApplyRange
listView.highlightRangeMode = ListView.StrictlyEnforceRange
listView.currentIndex = i
postScrollDeferTimer.restart()
break
Expand Down Expand Up @@ -86,6 +86,14 @@ Item {
// displayMarginBeginning: -45
clip: true
focus: true
onActiveFocusChanged: {
if (activeFocus) {
// When focus in, we always scroll to the highlight
listView.highlightMoveDuration = 0
listView.highlightRangeMode = ListView.StrictlyEnforceRange
postScrollDeferTimer.restart()
}
}

section.property: CategorizedSortProxyModel.sortRoleName // "transliterated" // "category"
section.criteria: section.property === "transliterated" ? ViewSection.FirstCharacter : ViewSection.FullString
Expand Down
19 changes: 17 additions & 2 deletions qml/GridViewContainer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,31 @@ FocusScope {
height: rows == 0 ? parent.height : (item.cellSize * root.rows)
color: "transparent"

Timer {
id: postScrollDeferTimer
interval: 150
onTriggered: {
gridView.highlightMoveDuration = 150
gridView.highlightRangeMode = GridView.NoHighlightRange
}
}

GridView {
id: gridView
anchors.fill: parent
clip: true
highlightFollowsCurrentItem: true
keyNavigationEnabled: true
highlightMoveDuration: 0
highlightMoveDuration: 150
activeFocusOnTab: focus ? root.activeGridViewFocusOnTab : false
focus: count > 0

onActiveFocusChanged: {
if (activeFocus) {
gridView.highlightMoveDuration = 0
gridView.highlightRangeMode = GridView.StrictlyEnforceRange
postScrollDeferTimer.restart()
}
}
cellHeight: item.cellSize
cellWidth: item.cellSize

Expand Down

0 comments on commit a14c9bf

Please sign in to comment.