Official
files
Built-in files UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/files@0.2.6
Permissions in 0.2.6
Files
folders.ts2.4 KB
// The folders open in each workspace's tree. The panel keeps them rather
// than the kernel's tree, so they outlast the tree: a hidden panel or
// another workspace gives them back as they were. The folders of the
// visible file open too, as in Zed.
import * as Effect from "effect/Effect";
import { folderIds } from "./panel.ts";
import type { FilesState } from "./panel.ts";
// `list` lists one folder of a workspace, warning when it cannot; `redraw`
// draws the panel again.
export function makeFolders(
state: FilesState,
list: (workspaceId: string, folder: string) => Effect.Effect<void>,
redraw: () => void,
) {
const openIn = (workspaceId: string) => (state.open[workspaceId] ??= new Set());
// Opening a folder whose listing failed tries again, "Loading…" meanwhile.
const expand = Effect.fn("Files.expand")(function* (workspaceId: string, folder: string) {
if (state.all || state.listing[folder]) return;
if (state.failed.has(folder)) {
state.failed = new Set([...state.failed].filter((id) => id !== folder));
redraw();
}
yield* list(workspaceId, folder);
});
// A folder opened or closed in the tree, by pointer or keyboard. The tree
// shows it already; the panel keeps it for when the tree is drawn anew.
const setOpen = Effect.fn("Files.setOpen")(function* (workspaceId: string, folder: string, open: boolean) {
if (!open) return void openIn(workspaceId).delete(folder);
openIn(workspaceId).add(folder);
yield* expand(workspaceId, folder);
});
const collapseAll = Effect.fn("Files.collapseAll")(function* () {
if (!state.workspaceId) return;
openIn(state.workspaceId).clear();
redraw();
});
// Opens each folder on the file's path that its parent lists, listing the
// parents on the way, so a file of another workspace opens nothing.
const reveal = Effect.fn("Files.reveal")(function* (path: string) {
const workspaceId = state.workspaceId;
if (!workspaceId || state.all) return;
let parent = "";
for (const folder of folderIds(path)) {
if (!state.listing[parent]) yield* list(workspaceId, parent);
if (!state.listing[parent]?.folders.includes(folder.slice(parent.length, -1))) break;
openIn(workspaceId).add(folder);
parent = folder;
}
if (parent) yield* expand(workspaceId, parent);
redraw();
});
return { openIn, setOpen, collapseAll, reveal };
}
No comments yet.