Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions qml/windowed/FreeSortListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ Item {
root.animationEnabled = true
}
}

Timer {
id: delayedResetTimer
interval: 50
repeat: true
onTriggered: {
Comment on lines +30 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Polling with a repeating timer for model.count > 0 could be brittle and wasteful.

This 50ms repeating timer is effectively a tight polling loop on model.count. If the model is late to populate or never does, it runs indefinitely and assumes model.count is always readable. Prefer an event-driven approach, e.g. listening to a model.countChanged-style signal, or using a one-shot Timer you restart from resetViewState() while count === 0 to avoid continuous polling.

Suggested implementation:

    // One-shot timer used as a deferred reset trigger. It is started from
    // resetViewState() while the model is still empty, instead of polling
    // continuously with a repeating timer.
    Timer {
        id: delayedResetTimer
        interval: 50
        repeat: false
        onTriggered: {
            // Only reset once the model is populated; otherwise the caller
            // (resetViewState) may choose to reschedule this timer.
            if (listView.model && listView.model.count > 0) {
                resetViewState()
            }
        }
    }

To fully implement the suggested behavior (avoiding continuous polling and only using a one-shot timer while count === 0), you should also update resetViewState() in this file:

  1. At the beginning of resetViewState(), add logic like:

    • If !listView.model || listView.model.count === 0, call delayedResetTimer.start() and return early.
    • Otherwise, perform the normal reset logic immediately.
  2. Ensure that no other code calls delayedResetTimer.start() in a loop or independently of resetViewState(), so the timer is only used as a deferred one-shot when the model is empty.

This will make the reset behavior event-driven from the caller’s perspective and avoid having an always-repeating 50ms polling timer.

if (listView.model.count > 0) {
delayedResetTimer.stop()
resetViewState()
}
}
}

Component.onCompleted: {
enableAnimationTimer.start()
resetViewState()
}

onFocusChanged: () => {
Expand All @@ -40,11 +53,16 @@ Item {
}

function resetViewState() {
if (listView.model.count === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个好像不对?listView.model 是 FreeSortProxyModel,不是 DelegateModel,没有 count 属性

delayedResetTimer.start()
return
}
// 临时禁用highlightFollowsCurrentItem以避免动画
let wasFollowing = listView.highlightFollowsCurrentItem
listView.highlightFollowsCurrentItem = false
listView.currentIndex = 0
listView.contentY = 0
listView.positionViewAtIndex(0, ListView.Beginning)
listView.highlightFollowsCurrentItem = wasFollowing
}

Expand Down
22 changes: 12 additions & 10 deletions qml/windowed/WindowedFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,18 @@ InputEventItem {
Connections {
target: LauncherController
function onVisibleChanged() {
// only do these clean-up steps on launcher get hide
if (LauncherController.visible) return

// clear searchEdit text
bottomBar.searchEdit.text = ""
// reset(remove) keyboard focus
baseLayer.focus = true
// reset scroll area position and state
appList.resetViewState()
folderGridViewPopup.close()
if (LauncherController.visible) {
appList.resetViewState()
} else {
// only do these clean-up steps on launcher get hide
// clear searchEdit text
bottomBar.searchEdit.text = ""
// reset(remove) keyboard focus
baseLayer.focus = true
// reset scroll area position and state
appList.resetViewState()
folderGridViewPopup.close()
}
}
}

Expand Down