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:
1 parent
de9b863f3f
commit
2a41cde6f5
1 file changed
+23
-5
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user