mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(explorer): apply directory toggles atomically
This commit is contained in:
@@ -42,6 +42,7 @@ import {
|
||||
flattenExplorerTree,
|
||||
reconcileRestoredExpandedPaths,
|
||||
restoreExpandedDirectories,
|
||||
setExpandedDirectoryPath,
|
||||
showHiddenFilesAndRestoreExpandedDirectories,
|
||||
type ExplorerTreeRow,
|
||||
} from "@/file-explorer/tree";
|
||||
@@ -755,15 +756,14 @@ function toggleDirectory({
|
||||
return;
|
||||
}
|
||||
const isExpanded = expandedPaths.has(entry.path);
|
||||
if (isExpanded) {
|
||||
setExpandedPathsForWorkspace(
|
||||
workspaceStateKey,
|
||||
Array.from(expandedPaths).filter((path) => path !== entry.path),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setExpandedPathsForWorkspace(workspaceStateKey, [...Array.from(expandedPaths), entry.path]);
|
||||
if (!directories.has(entry.path)) {
|
||||
setExpandedPathsForWorkspace(workspaceStateKey, (currentPaths) =>
|
||||
setExpandedDirectoryPath({
|
||||
currentExpandedPaths: currentPaths,
|
||||
directoryPath: entry.path,
|
||||
expanded: !isExpanded,
|
||||
}),
|
||||
);
|
||||
if (!isExpanded && !directories.has(entry.path)) {
|
||||
void requestDirectoryListing(entry.path, {
|
||||
recordHistory: false,
|
||||
setCurrentPath: false,
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
flattenExplorerTree,
|
||||
reconcileRestoredExpandedPaths,
|
||||
restoreExpandedDirectories,
|
||||
setExpandedDirectoryPath,
|
||||
showHiddenFilesAndRestoreExpandedDirectories,
|
||||
} from "./tree";
|
||||
|
||||
@@ -153,6 +154,22 @@ describe("file explorer tree", () => {
|
||||
expect(paths).toEqual([".", "manual"]);
|
||||
});
|
||||
|
||||
it("applies a directory click to the latest restored expansion paths", () => {
|
||||
const expanded = setExpandedDirectoryPath({
|
||||
currentExpandedPaths: [".", "restored"],
|
||||
directoryPath: "manual",
|
||||
expanded: true,
|
||||
});
|
||||
const collapsed = setExpandedDirectoryPath({
|
||||
currentExpandedPaths: expanded,
|
||||
directoryPath: "manual",
|
||||
expanded: false,
|
||||
});
|
||||
|
||||
expect(expanded).toEqual([".", "restored", "manual"]);
|
||||
expect(collapsed).toEqual([".", "restored"]);
|
||||
});
|
||||
|
||||
it("shows hidden files before waiting for expanded directories to restore", async () => {
|
||||
const rootDirectory = {
|
||||
path: ".",
|
||||
|
||||
@@ -36,6 +36,12 @@ interface ReconcileRestoredExpandedPathsInput {
|
||||
restoredExpandedPaths: string[];
|
||||
}
|
||||
|
||||
interface SetExpandedDirectoryPathInput {
|
||||
currentExpandedPaths: readonly string[];
|
||||
directoryPath: string;
|
||||
expanded: boolean;
|
||||
}
|
||||
|
||||
export function flattenExplorerTree({
|
||||
directories,
|
||||
expandedPaths,
|
||||
@@ -153,6 +159,20 @@ export function reconcileRestoredExpandedPaths({
|
||||
return Array.from(reconciledPaths);
|
||||
}
|
||||
|
||||
export function setExpandedDirectoryPath({
|
||||
currentExpandedPaths,
|
||||
directoryPath,
|
||||
expanded,
|
||||
}: SetExpandedDirectoryPathInput): string[] {
|
||||
const nextPaths = new Set(currentExpandedPaths);
|
||||
if (expanded) {
|
||||
nextPaths.add(directoryPath);
|
||||
} else {
|
||||
nextPaths.delete(directoryPath);
|
||||
}
|
||||
return Array.from(nextPaths);
|
||||
}
|
||||
|
||||
function rowsForDirectory(
|
||||
directory: ExplorerDirectory,
|
||||
depth: number,
|
||||
|
||||
Reference in New Issue
Block a user