fix(sftp): retain selection reveal after explicit view changes

This commit is contained in:
bincxz committed 2026-09-12 17:17:20 +08:00
1 parent ce86e8e426
commit f9ad1ddfe0
2 files changed
+69 -6

No files matched your search

+17 -6
View File
@@ -196,12 +196,23 @@ export const SftpPaneFileList: React.FC<SftpPaneFileListProps> = React.memo(({
return () => sftpListOrderStore.clearPane(pane.id);
}, [sortedDisplayFiles, pane.id]);
const lastScrolledSelectionRef = useRef<Set<string> | null>(null);
const selectionScrollContext = useMemo(() => ({
paneId: pane.id, filter: pane.filter, showHiddenFiles: pane.showHiddenFiles,
sortField, sortOrder, directoriesFirst, rowHeight, shouldVirtualize,
}), [
pane.id, pane.filter, pane.showHiddenFiles, sortField, sortOrder,
directoriesFirst, rowHeight, shouldVirtualize,
]);
const lastScrolledSelectionRef = useRef<{
selection: Set<string>;
context: object;
} | null>(null);
useEffect(() => {
// A same-directory refresh retains the selection object. Do not pull the
// viewport back to an old selection when the user has scrolled elsewhere.
if (lastScrolledSelectionRef.current === pane.selectedFiles) return;
lastScrolledSelectionRef.current = pane.selectedFiles;
// Refreshes preserve selection identity; explicit sorting/filter/layout
// changes still reveal the selected row using the usual behavior.
const last = lastScrolledSelectionRef.current;
if (last?.selection === pane.selectedFiles && last.context === selectionScrollContext) return;
lastScrolledSelectionRef.current = { selection: pane.selectedFiles, context: selectionScrollContext };
if (pane.selectedFiles.size !== 1) return;
const selectedName = Array.from(pane.selectedFiles)[0];
if (!selectedName) return;
@@ -225,7 +236,7 @@ export const SftpPaneFileList: React.FC<SftpPaneFileListProps> = React.memo(({
currentScrollTop: container.scrollTop,
viewportHeight: container.clientHeight,
});
}, [fileListRef, pane.selectedFiles, rowHeight, shouldVirtualize, sortedDisplayFiles]);
}, [fileListRef, pane.selectedFiles, rowHeight, selectionScrollContext, shouldVirtualize, sortedDisplayFiles]);
// Use refs for frequently-changing values in context-menu actions
const selectedFilesRef = useRef(pane.selectedFiles);