From 2a41cde6f5853df783ac49ab545a795ee9406561 Mon Sep 17 00:00:00 2001 From: mx Date: Sun, 8 Nov 2026 22:54:13 +0100 Subject: [PATCH] Keep the picker's selection when a rescan replaces the grid Co-Authored-By: Claude Opus 5.5 --- quickshell/wallpaper/WallpaperPicker.qml | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/quickshell/wallpaper/WallpaperPicker.qml b/quickshell/wallpaper/WallpaperPicker.qml index ae9d0b4..adf90c8 100644 --- a/quickshell/wallpaper/WallpaperPicker.qml +++ b/quickshell/wallpaper/WallpaperPicker.qml @@ -45,10 +45,25 @@ PanelWindow { view.currentIndex=index; selectedPath=results[index].path; } + // Puts the view back on the selection after its model was replaced. The + // selection only changes on input (select/step), never from the view. + property bool centerOnSync:false function syncSelection() { const index=results.findIndex(i=>i.path===selectedPath); - if(index>=0)view.currentIndex=index; - else if(results.length)select(0); + view.currentIndex=index; + if(index>=0 && centerOnSync) {view.positionViewAtIndex(index,GridView.Center);centerOnSync=false;} + } + // Arrow keys: move in the grid; from no selection, start at the first tile. + function step(move) { + if(!results.length)return; + if(view.currentIndex<0)view.currentIndex=0; + else move(); + selectedPath=results[view.currentIndex].path; + } + // A search that hides the selection selects its first match. + Connections { + target:search + function onTextChanged() {if(search.text && !root.selected && root.results.length)root.select(0);} } onResultsChanged:Qt.callLater(syncSelection) // Previews follow the selection once it rests, so sweeping across the grid @@ -77,8 +92,8 @@ PanelWindow { preview.instantNext=true; preview.path=desktopPath; selectedPath=desktopPath; + centerOnSync=true; syncSelection(); - view.positionViewAtIndex(Math.max(0,view.currentIndex),GridView.Center); Qt.callLater(()=>view.forceActiveFocus()); } } @@ -189,9 +204,12 @@ PanelWindow { clip:true model:root.results boundsBehavior:Flickable.StopAtBounds - keyNavigationEnabled:true + keyNavigationEnabled:false ScrollBar.vertical:ScrollBar {} - onCurrentIndexChanged:if(root.results[currentIndex])root.selectedPath=root.results[currentIndex].path + Keys.onLeftPressed:root.step(()=>view.moveCurrentIndexLeft()) + Keys.onRightPressed:root.step(()=>view.moveCurrentIndexRight()) + Keys.onUpPressed:root.step(()=>view.moveCurrentIndexUp()) + Keys.onDownPressed:root.step(()=>view.moveCurrentIndexDown()) Keys.onReturnPressed:root.applySelected() Keys.onEnterPressed:root.applySelected() Keys.onEscapePressed:root.close()