дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
feat(project-view): restore the persisted expansion state as the user left it (#782)
The Project view restored only expanded paths inside the project roots and always re-expanded the roots. Restore the persisted state as is (a collapsed root stays collapsed, nodes outside it such as content roots stay open); only a first open expands the roots. Co-authored-by: ntbang0901 <[email protected]>
Цей коміт міститься в:
1 джерело
193e6a4840
коміт
47f68862c8
2 files changed
+14
-5
No files matched your search
@@ -68,6 +68,14 @@ describe("lazy loading", () => {
|
||||
expect([...useProjectTree.getState().expanded].sort()).toEqual(["/p", "/p/docs"]);
|
||||
});
|
||||
|
||||
it("keeps a collapsed project root collapsed and an expanded node outside it open", async () => {
|
||||
setExpanded(new Set(["/other/lib"]));
|
||||
await new Promise((r) => setTimeout(r, 350));
|
||||
initProjectTree(null);
|
||||
initProjectTree(ROOT, "proj");
|
||||
expect([...useProjectTree.getState().expanded]).toEqual(["/other/lib"]);
|
||||
});
|
||||
|
||||
it("drops a folder that vanished and collapses it", async () => {
|
||||
await loadDir(ROOT);
|
||||
setExpanded(new Set([ROOT, "/p/gone"]));
|
||||
|
||||
@@ -301,11 +301,12 @@ function initialExpanded(root: string | null, mode: ViewMode, members = get().me
|
||||
r.scope === "scratches" && r.path ? [r.path] : [],
|
||||
),
|
||||
);
|
||||
const persisted = mode === "project" ? (readJson<string[]>(expandedKey(root)) ?? []) : [];
|
||||
const roots = members ?? [root];
|
||||
const expanded = new Set(persisted.filter((p) => roots.some((r) => isSameOrInside(p, r))));
|
||||
roots.forEach((r) => expanded.add(r));
|
||||
return expanded;
|
||||
// The tree as the user left it, like IDEA: a collapsed project root stays collapsed, and
|
||||
// nodes outside it (content roots, contributed roots) stay open.
|
||||
// Keys of nodes that no longer exist are inert. Only a first open expands the roots.
|
||||
const persisted = mode === "project" ? readJson<string[]>(expandedKey(root)) : null;
|
||||
if (persisted) return new Set(persisted);
|
||||
return new Set(members ?? [root]);
|
||||
}
|
||||
|
||||
function persistExpanded() {
|
||||
|
||||
Reference in new issue
Заблокувати користувача