Keep the picker's selection when a rescan replaces the grid

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-08 22:54:13 +01:00
1 parent de9b863f3f
commit 2a41cde6f5
1 file changed
+23 -5
+23 -5
View File
@@ -45,10 +45,25 @@ PanelWindow {
view.currentIndex=index; view.currentIndex=index;
selectedPath=results[index].path; 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() { function syncSelection() {
const index=results.findIndex(i=>i.path===selectedPath); const index=results.findIndex(i=>i.path===selectedPath);
if(index>=0)view.currentIndex=index; view.currentIndex=index;
else if(results.length)select(0); 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) onResultsChanged:Qt.callLater(syncSelection)
// Previews follow the selection once it rests, so sweeping across the grid // Previews follow the selection once it rests, so sweeping across the grid
@@ -77,8 +92,8 @@ PanelWindow {
preview.instantNext=true; preview.instantNext=true;
preview.path=desktopPath; preview.path=desktopPath;
selectedPath=desktopPath; selectedPath=desktopPath;
centerOnSync=true;
syncSelection(); syncSelection();
view.positionViewAtIndex(Math.max(0,view.currentIndex),GridView.Center);
Qt.callLater(()=>view.forceActiveFocus()); Qt.callLater(()=>view.forceActiveFocus());
} }
} }
@@ -189,9 +204,12 @@ PanelWindow {
clip:true clip:true
model:root.results model:root.results
boundsBehavior:Flickable.StopAtBounds boundsBehavior:Flickable.StopAtBounds
keyNavigationEnabled:true keyNavigationEnabled:false
ScrollBar.vertical:ScrollBar {} 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.onReturnPressed:root.applySelected()
Keys.onEnterPressed:root.applySelected() Keys.onEnterPressed:root.applySelected()
Keys.onEscapePressed:root.close() Keys.onEscapePressed:root.close()