Skip to content

Commit 2fcd03e

Browse files
fix(web): defer file reveal acknowledgment until listings arrive
1 parent 64e28e2 commit 2fcd03e

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎apps/web/src/components/files/FileBrowserPanel.tsx‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,24 @@ export default function FileBrowserPanel({
511511
else handledRevealRef.current = null;
512512
return;
513513
}
514-
// Entry refreshes rebuild treePaths while the same preview stays open.
515-
// Replaying a handled reveal would close an active tree search and steal focus.
516-
if (sameReveal && !handledReveal.selectionMissing) return;
517514
const selectedTreePath = selectedKind === "directory" ? `${selectedPath}/` : selectedPath;
518515
const selectedItem = model.getItem(selectedTreePath);
519516
if (!selectedItem) return;
517+
const acknowledgeReveal = () => {
518+
// Search-only rows can disappear before their directory listings arrive.
519+
if (
520+
!selectedPathRevealHandled &&
521+
directoryEntries.some((entry) => entry.path === selectedPath)
522+
) {
523+
onSelectedPathRevealHandled();
524+
}
525+
};
526+
// Entry refreshes rebuild treePaths while the same preview stays open.
527+
// Replaying a handled reveal would close an active tree search and steal focus.
528+
if (sameReveal && !handledReveal.selectionMissing) {
529+
acknowledgeReveal();
530+
return;
531+
}
520532
// A retained preview needs selection in the new model without replaying its reveal.
521533
if (skipInitialReveal || (sameReveal && model.isSearchOpen())) {
522534
handledRevealRef.current = revealRequest;
@@ -525,6 +537,7 @@ export default function FileBrowserPanel({
525537
model.getItem(path)?.deselect();
526538
}
527539
selectedItem.select();
540+
acknowledgeReveal();
528541
queueMicrotask(() => {
529542
syncingSelectionRef.current = false;
530543
});
@@ -541,12 +554,11 @@ export default function FileBrowserPanel({
541554
if (selectedInTree && treeSelectionPathRef.current === selectedPath) {
542555
treeSelectionPathRef.current = null;
543556
handledRevealRef.current = revealRequest;
544-
onSelectedPathRevealHandled();
557+
acknowledgeReveal();
545558
return;
546559
}
547560
treeSelectionPathRef.current = null;
548561
handledRevealRef.current = revealRequest;
549-
onSelectedPathRevealHandled();
550562

551563
syncingSelectionRef.current = true;
552564
setQuery("");
@@ -571,14 +583,17 @@ export default function FileBrowserPanel({
571583
focus: true,
572584
offset: "center",
573585
});
586+
acknowledgeReveal();
574587
queueMicrotask(() => {
575588
syncingSelectionRef.current = false;
576589
});
577590
}, [
591+
directoryEntries,
578592
entryKinds,
579593
model,
580594
selectedPath,
581595
selectedPathRevealId,
596+
selectedPathRevealHandled,
582597
shouldSkipInitialReveal,
583598
onSelectedPathRevealHandled,
584599
]);

0 commit comments

Comments
 (0)