Official
palette
Built-in command palette (⌘⇧P) and chat search (⌘P).
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/palette@0.2.5
Permissions in 0.2.5
Files
state.ts2.7 KB
// Palette state belongs to one activation; ranking and rendering share it through this layer.
// Its view handle lets asynchronous catalog and search results request a render.
import * as Context from "effect/Context";
import * as Layer from "effect/Layer";
import type { EffectClient } from "divergence/effect";
import type { Chat, CommandInfo, Element, PaletteItem, PaletteProviderInfo, ViewHandle, Workspace } from "divergence";
import type { Row } from "./controller.ts";
import type { Settings } from "../settings/contract.ts";
export interface State {
open: "commands" | "chats" | null;
// The palette a key press asked for while its lists are on their way,
// and the ticket of the latest press.
pending: "commands" | "chats" | null;
opening: number;
query: string;
// What the chat search held when it last closed, and when: opened again
// within KEEP_FOR_MS it shows the same text.
kept: { query: string; at: number } | null;
selected: number;
// The row at the top of the list, as the kernel last said (`onRange`).
top: number;
commands: readonly CommandInfo[];
// Every chat by id, kept current by the host's chat events once loaded.
chats: Map<string, Chat>;
// The tasks the user checked off, whose chats show a check.
done: Set<string>;
// Counts the changes to `chats` and `done`, which are edited in place.
chatsRevision: number;
chatsLoaded: boolean;
workspaces: Record<string, Workspace>;
providers: readonly PaletteProviderInfo[];
found: { key: string; items: readonly PaletteItem[] };
recent: string[];
searching: number;
view?: ViewHandle;
// The divergence/settings client while its provider runs; Assign on a
// conflicting key does nothing without it.
settings: EffectClient<typeof Settings> | undefined;
// Each row's element, kept while its row is: a row that did not change is
// the same object as last time, which the runtime does not walk again, so
// an arrow key costs only the selection's fill and the scroller's reveal.
// Rows close over this activation, so they are kept here and not in a
// module, which outlives a reload and would keep every earlier activation.
drawn: WeakMap<Row, Element>;
}
export class PaletteState extends Context.Service<PaletteState, State>()("palette/State") {
static readonly layer = Layer.sync(PaletteState, () => ({
open: null,
pending: null,
opening: 0,
query: "",
kept: null,
selected: 0,
top: 0,
commands: [],
chats: new Map(),
done: new Set<string>(),
chatsRevision: 0,
chatsLoaded: false,
workspaces: {},
providers: [],
found: { key: "", items: [] },
recent: [],
searching: 0,
settings: undefined,
drawn: new WeakMap(),
}));
}
No comments yet.