Forks in the panes view: Shift+Enter or a modified click opens beside, not instead

The store's trail becomes the focused branch of the tree of forks. Shift+Enter,
Shift-, Ctrl-, Cmd- or middle-click opens a pane as a new fork; a plain open
replaces the focused fork, or focuses a fork already open. Right of a pane with
forks the space divides into rows that share the height down to a third each
and then scroll, the pane they came from staying at the top; the strip still
scrolls sideways as one. The parent marks each fork's row, link or words, the
focused one as before. [ and ] move between forks, back where the reader was;
q closes a whole fork at its end. A click in another fork focuses it. Too short
or narrow a window draws only the focused branch and says which fork it is.
A plain trail renders exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-15 22:48:10 -05:00
1 parent e733e131bb
commit 207002410b
9 files changed
+863 -143

No files matched your search

+272 -59
View File
@@ -36,6 +36,7 @@ import { remoteLLM } from "./remote";
import { Session } from "./session";
import { refreshAfterCalls } from "./usage";
import { Linker, type AutoMode, type JobState, type Sugg } from "./linker";
import { all, chain, closeAt, closeChild, closeRight, open as openIn, path, prune, restore as restoreTree, save as saveTree, select, sibling, trace, update, withBranch, type Tree } from "./forks";
import { stripMarks, type Mark } from "../core/marks";
import { SEED_SLUG } from "../core/seed";
@@ -48,10 +49,10 @@ export interface Focus {
export type Mode = "normal" | "edit" | "command" | "history" | "help" | "jump" | "docs" | "link" | "review";
/**
* A pane of the panes view. The strip is a trail: it starts with the path down from the top node,
* and a link followed from a pane opens its target in the next pane, so it may hold another
* document's node, a Wikipedia article or a section of one. `from` is where a jump was made from,
* which h returns to.
* A pane of the panes view. The panes are a tree of forks (forks.ts) whose focused branch is the
* trail: it starts with the path down from the top node, and a link followed from a pane opens its
* target in the next pane, so it may hold another document's node, a Wikipedia article or a section
* of one. `from` is where a jump was made from, which h returns to.
*/
export type PaneRef =
| { kind: "node"; id: NodeId; from?: Back }
@@ -61,6 +62,17 @@ export interface Back {
aux: Aux | null;
pane: number;
}
/** A pane in the tree of forks; `seen` is where the reader was when they last left its fork. */
export type Pane = Tree<PaneRef, Back>;
/** Whether two panes show the same thing (a node, or an article or one of its sections). */
export const sameRef = (a: PaneRef, b: PaneRef): boolean =>
a.kind === b.kind && (a.kind === "node" ? a.id === (b as { id: NodeId }).id : a.title === (b as { title: string }).title && a.sec === (b as { sec?: number }).sec);
/** What a pane shows, as a key: `n:<node id>`, or `w:<title>` with `#<section>`. A link's target has the same key as the pane it opens. */
export const refKey = (p: PaneRef): string => (p.kind === "node" ? `n:${p.id}` : `w:${p.title}${p.sec !== undefined ? `#${p.sec}` : ""}`);
const isPaneRef = (r: unknown): r is PaneRef => {
const o = r as Record<string, unknown> | null;
return !!o && typeof o === "object" && ((o.kind === "node" && typeof o.id === "string") || (o.kind === "wiki" && typeof o.title === "string" && typeof o.lang === "string"));
};
/** A row of a Wikipedia view: its head (the lead), a section, a sense of a disambiguation page, a "Mentioned in" entry. */
export type WRow = { t: "head" } | { t: "sec"; id: number } | { t: "sense"; i: number } | { t: "back"; i: number };
/**
@@ -232,9 +244,28 @@ class Store {
/** Replicas of pre-library documents whose edits never reached the server. */
oldReplicas: OldReplica[] = [];
/** The panes, left to right, and which one holds the focus. */
trail: PaneRef[] = [];
/** The panes as a tree of forks; its focused branch is `trail`, and `paneAt` is the pane on it that holds the focus. */
tree: Pane | null = null;
paneAt = 0;
/** Set while a modified open (Shift+Enter, Shift-, Ctrl- or middle-click) runs: it opens a fork beside what is there. */
forking = false;
private toldForks = false;
private memo: { tree: Pane | null; nodes: Pane[]; trail: PaneRef[]; index?: Map<number, { node: Pane; depth: number }>; ids?: Set<NodeId> } = { tree: null, nodes: [], trail: [] };
private get branch() {
if (this.memo.tree !== this.tree) {
const nodes = path(this.tree);
this.memo = { tree: this.tree, nodes, trail: nodes.map((n) => n.ref) };
}
return this.memo;
}
/** The focused branch: the panes the keys move along, left to right. */
get trail(): PaneRef[] {
return this.branch.trail;
}
/** The focused branch as nodes of the tree. */
get branchNodes(): Pane[] {
return this.branch.nodes;
}
aux: Aux | null = null;
colWiki: ColWiki | null = null;
/** Sections of the column's article page that are open. */
@@ -398,58 +429,219 @@ class Store {
/** Whether pane i continues the one before it (a section opened from its row) rather than being a jump. */
continues(i: number): boolean {
const p = this.trail[i];
const q = this.trail[i - 1];
return this.continuesFrom(this.trail[i], this.trail[i - 1]);
}
/** Whether pane p continues pane q, the one it was opened from. */
continuesFrom(p: PaneRef | undefined, q: PaneRef | undefined): boolean {
if (!p || !q || p.from) return false;
if (p.kind === "node") return q.kind === "node" && this.snap.nodes[p.id]?.parent === q.id && this.snap.nodes[p.id].kind === "section";
return p.sec !== undefined && (q.kind === "wiki" ? q.title === p.title : this.targetOf(q.id)?.kind === "wiki");
}
/**
* Whether pane i holds a focus: its node's text (a selection, a note in it), one of its rows, or
* its head when it is not a continuation (a continuation's node is focused as the row it was
* opened from, in the pane before).
*/
/** Pane i of the focused branch holds a focus (see holdsIn). */
private holds(i: number, f: Focus): boolean {
const p = this.trail[i];
return this.holdsIn(this.trail[i], this.trail[i - 1], i === 0, `p${i}`, f);
}
/**
* Whether a pane (p, opened from q; host: how its article is named) holds a focus: its node's
* text (a selection, a note in it), one of its rows, or its head when it is not a continuation (a
* continuation's node is focused as the row it was opened from, in the pane before).
*/
private holdsIn(p: PaneRef | undefined, q: PaneRef | undefined, first: boolean, host: string, f: Focus): boolean {
const s = this.snap;
const n = s.nodes[f.node];
// An annotation is held by the pane showing its article.
if (p && n && inArticles(s, f.node)) return this.shows(p.kind === "wiki" ? `p${i}` : `n${p.id}`, f.node);
if (p && n && inArticles(s, f.node)) return this.shows(p.kind === "wiki" ? host : `n${p.id}`, f.node);
if (!p || p.kind !== "node" || !n) return false;
if (f.grain !== "node" || n.kind === "note") return ownerSection(s, f.node) === p.id || f.node === p.id;
if (f.node === p.id) return i === 0 || !this.continues(i);
if (f.node === p.id) return first || !this.continuesFrom(p, q);
return n.parent === p.id;
}
/** A pane off the focused branch that holds a focus: the tree with it on the branch, and its column. */
private forkHolding(f: Focus): { tree: Pane; depth: number } | null {
const t = this.tree;
if (!t) return null;
const on = new Set(this.branchNodes.map((n) => n.id));
const find = (n: Pane, q: PaneRef | undefined, d: number): { id: number; depth: number } | null => {
if (!on.has(n.id) && this.holdsIn(n.ref, q, d === 0, `f${n.id}`, f)) return { id: n.id, depth: d };
for (const k of n.kids) {
const hit = find(k, n.ref, d + 1);
if (hit) return hit;
}
return null;
};
const hit = find(t, undefined, 0);
return hit ? { tree: select(t, hit.id)!, depth: hit.depth } : null;
}
/**
* Change the tree. When the focused branch leaves a fork that stays open, the fork remembers
* where the reader was in it, for [ and ] to come back to.
*/
private setTree(next: Pane | null, remember = true) {
const old = this.branchNodes;
if (next && remember && old.length) {
const now = path(next);
const d = old.findIndex((n, k) => now[k]?.id !== n.id);
if (d > 0 && trace(next, old[d].id)) {
const here = this.backHere();
next = update(next, old[d].id, (n) => ({ ...n, seen: here }));
}
}
this.tree = next;
}
/** The panes as a plain trail down to the focus (open sections on the way). */
private pathRefs(): PaneRef[] {
return this.panePath().map((id) => ({ kind: "node" as const, id }));
}
/**
* Keep the trail holding the focus. Moving within the panes (back left, along a pane's rows)
* leaves the trail as it is; only when the focus lands somewhere no pane holds (a jump from the
* search box, a reload at an address) is the trail made again as the path down to it.
* leaves the trail as it is. When the focus lands somewhere the focused branch does not hold, a
* fork that holds it becomes the focused branch (Back to a pane in it, a click in it); failing
* that (a jump from the search box, a reload at an address) the branch is made again as the path
* down to it, keeping whatever forks are off that path. Panes of deleted nodes close, in any fork.
*/
syncTrail() {
if (!this.panes || !this.session) return;
const s = this.snap;
if (!this.trail.length || this.trail[0].kind !== "node" || this.trail[0].id !== this.top) this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
const gone = this.trail.findIndex((p) => p.kind === "node" && !s.nodes[p.id]);
if (gone > 0) this.trail = this.trail.slice(0, gone);
let t = prune(this.tree, (p) => p.kind === "wiki" || !!s.nodes[p.id]);
if (!t || t.ref.kind !== "node" || t.ref.id !== this.top) t = chain(this.pathRefs());
if (t !== this.tree) this.setTree(t, false);
this.paneAt = Math.max(0, Math.min(this.paneAt, this.trail.length - 1));
if (this.aux) return;
const n = this.trail.length;
const order = [this.paneAt, this.paneAt + 1, this.paneAt - 1, ...Array.from({ length: n }, (_, i) => i)];
for (const i of order) if (i >= 0 && i < n && this.holds(i, this.focus)) return void (this.paneAt = i);
this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
const fork = this.forkHolding(this.focus);
if (fork) {
this.setTree(fork.tree, false);
this.paneAt = fork.depth;
return;
}
this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
const at = this.trail.findIndex((_, i) => this.holds(i, this.focus));
this.paneAt = at >= 0 ? at : this.trail.length - 1;
}
/** Open something in the pane after pane i: what was to the right of it goes, unless it is already there. */
openPane(i: number, ref: PaneRef) {
const next = this.trail[i + 1];
const same = next && next.kind === ref.kind && (next.kind === "node" ? next.id === (ref as { id: NodeId }).id : next.title === (ref as { title: string }).title && next.sec === (ref as { sec?: number }).sec);
if (!same) this.trail = [...this.trail.slice(0, i + 1), ref];
/**
* Open something to the right of pane i. If it is already open there, as any fork, that fork is
* focused. Otherwise a plain open replaces what was to the right; a fork (`forking`) opens it
* beside that, as a new row below. Returns the pane it is in.
*/
openPane(i: number, ref: PaneRef): number {
this.setTree(this.tree ? openIn(this.tree, i, ref, this.forking, sameRef) : chain([ref]));
this.saveView();
this.emit();
return Math.min(i + 1, this.trail.length - 1);
}
/** Close the pane that shows this node to the right of pane i (whichever fork it is). */
closeRow(i: number, id: NodeId) {
if (!this.tree) return;
this.setTree(closeChild(this.tree, i, { kind: "node", id }, sameRef));
this.saveView();
this.emit();
}
/** Run an open with or without a fork. In the column a fork is a plain open, and the status line says so once. */
withFork<T>(fork: boolean, fn: () => T): T {
if (fork && !this.panes && !this.toldForks) {
this.toldForks = true;
this.say("Forks (Shift+Enter, Shift- or Ctrl-click) open side by side in the panes view; in one column this opens as usual.");
}
const was = this.forking;
this.forking = fork && this.panes;
try {
return fn();
} finally {
this.forking = was;
}
}
/** The tree's panes by id, with their columns. */
forkNode(id: number): { node: Pane; depth: number } | undefined {
const m = this.branch;
if (!m.index) m.index = new Map(all(this.tree).map((x) => [x.node.id, x]));
return m.index.get(id);
}
/** Whether any pane in the tree shows this node. */
private paneShows(id: NodeId): boolean {
const m = this.branch;
if (!m.ids) m.ids = new Set(all(this.tree).flatMap((x) => (x.node.ref.kind === "node" ? [x.node.ref.id] : [])));
return m.ids.has(id);
}
/** Whether some pane has forks. */
hasForks(): boolean {
return all(this.tree).some((x) => x.node.kids.length > 1);
}
/**
* For a pane with forks: its children by what they show (refKey), each true if it is the picked
* one. Null for a pane with one child or none, which marks nothing new (its row is marked as before).
*/
forkMarks(tid: number | undefined): Map<string, boolean> | null {
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
if (!n || n.kids.length < 2) return null;
return new Map(n.kids.map((k, j) => [refKey(k.ref), j === n.pick]));
}
/** A link's target by the key of the pane it opens (refKey); none for a web page or a node that is gone. */
targetKey(r: Ref): string | undefined {
if (r.kind === "wiki") return `w:${r.title}`;
if (r.kind !== "node") return undefined;
const id = resolveNode(this.snap, r);
return id ? `n:${id}` : undefined;
}
/** How a child is marked in the pane it was opened from: "showing" (the picked child), "forked" (another fork), or not open. */
kidMark(tid: number | undefined, match: (r: PaneRef) => boolean): "showing" | "forked" | undefined {
const n = tid === undefined ? undefined : this.forkNode(tid)?.node;
const k = n ? n.kids.findIndex((c) => match(c.ref)) : -1;
return k < 0 ? undefined : k === n!.pick ? "showing" : "forked";
}
/**
* Put the focus on pane c of the focused branch: on its node (for a continuation, that is the row
* it was opened from, in the pane before), or on an article's head.
*/
land(c: number) {
const p = this.trail[c];
if (!p) return;
this.paneAt = c;
if (p.kind === "node") this.setFocus({ node: p.id, grain: "node" });
else this.setFocus(this.focus, { kind: "wiki", host: `p${c}`, row: { t: "head" } });
}
/** A click in a pane off the focused branch: its fork becomes the focused branch, with the focus on that pane. */
enterFork(id: number) {
const hit = this.forkNode(id);
const t = this.tree && select(this.tree, id);
if (!hit || !t || t === this.tree) return;
this.setTree(t);
this.land(hit.depth);
}
/**
* [ and ]: the fork above or below, in the order the rows are drawn (the nearest pane, from the
* branch's end leftwards, that has another fork that way). The focus goes back where it was in
* that fork, or to its pane nearest the column the reader was in.
*/
focusFork(delta: number) {
if (!this.panes) return this.say("Forks are side by side in the panes view (v); one column shows one page.");
this.syncTrail();
const s = this.tree && sibling(this.tree, delta);
if (!s) return this.say(this.hasForks() ? `No fork ${delta < 0 ? "above" : "below"} this one.` : "No forks open. Shift+Enter, or a Shift- or Ctrl-click, opens one beside the pane to the right.");
const col = this.paneAt + (this.showingFocus() ? 1 : 0);
this.setTree(s.tree);
const b = this.branchNodes[s.depth].seen;
if (b && b.pane >= s.depth && b.pane < this.trail.length && this.snap.nodes[b.focus.node] && (b.aux ? this.auxValid(b.aux) : this.holds(b.pane, b.focus))) return this.restore(b);
this.land(Math.max(s.depth, Math.min(col, this.trail.length - 1)));
}
/** Whether the focus is a row whose pane is open next to it (so that pane is the one the reader is looking at). */
@@ -459,27 +651,34 @@ class Store {
}
/**
* q: close the panes to the right of the one the reader is looking at (for a row, the pane it
* shows); with none there, close that pane and step left.
* q, on the pane the reader is looking at (for a row, the pane it shows): close the panes to its
* right, every fork among them. With none there, close it and step left; in a fork, that closes
* the whole fork (from where it branched off to its end), and the others stay.
*/
closePane() {
const showing = this.showingFocus();
const i = this.paneAt + (showing ? 1 : 0);
if (!this.tree) return;
if (i + 1 < this.trail.length) {
this.trail = this.trail.slice(0, i + 1);
this.setTree(closeRight(this.tree, i));
this.saveView();
return this.emit();
}
if (i === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
const from = this.trail[i].from;
this.trail = this.trail.slice(0, i);
// The nearest pane to the left with forks: the fork the reader is in starts right of it.
const nodes = this.branchNodes;
let j = i - 1;
while (j >= 0 && nodes[j].kids.length < 2) j--;
const k = j >= 0 ? j + 1 : i;
if (k === 0) return this.say("The first pane stays; h or Esc at its top steps out of it.");
const from = this.trail[k].from;
this.setTree(closeAt(this.tree, k));
this.saveView();
if (showing) return this.emit();
this.paneAt = i - 1;
if (from && from.pane < i) return this.restore(from);
const p = this.trail[i - 1];
if (showing && k === i) return this.emit();
this.paneAt = k - 1;
if (from && from.pane < k) return this.restore(from);
const p = this.trail[k - 1];
if (p.kind === "node") this.setFocus({ node: p.id, grain: "node" });
else this.setFocus(this.focus, { kind: "wiki", host: `p${i - 1}`, row: { t: "head" } });
else this.setFocus(this.focus, { kind: "wiki", host: `p${k - 1}`, row: { t: "head" } });
}
/** Go back to where a jump was made from. */
@@ -520,7 +719,7 @@ class Store {
* top, a pane's node), not under every open node, which would fill the page with lists.
*/
relatedShown(id: NodeId): boolean {
if (this.panes) return this.trail.some((p) => p.kind === "node" && p.id === id);
if (this.panes) return this.paneShows(id);
return id === this.focus.node || id === this.top;
}
@@ -567,14 +766,18 @@ class Store {
if (a.kind !== "wiki") return !!this.snap.nodes[a.of];
if (a.host === "col") return !!this.colWiki;
if (a.host.startsWith("p")) return this.trail[+a.host.slice(1)]?.kind === "wiki";
if (a.host.startsWith("f")) return false;
return !!this.snap.nodes[a.host.slice(1) as NodeId];
}
/** The article a Wikipedia host shows, and how. */
/**
* The article a Wikipedia host shows, and how. `p<i>` is the article pane at column i of the
* focused branch, `f<id>` an article pane off it (by its id in the tree of forks).
*/
wikiHost(host: string): { title: string; lang: string; sec: number; embedded?: NodeId; nested?: boolean; mentions?: boolean } | null {
if (host === "col") return this.colWiki ? { title: this.colWiki.title, lang: this.colWiki.lang, sec: 0, nested: true, mentions: true } : null;
if (host.startsWith("p")) {
const p = this.trail[+host.slice(1)];
if (host.startsWith("p") || host.startsWith("f")) {
const p = host.startsWith("p") ? this.trail[+host.slice(1)] : this.forkNode(+host.slice(1))?.node.ref;
return p?.kind === "wiki" ? { title: p.title, lang: p.lang, sec: p.sec ?? 0, mentions: p.sec === undefined } : null;
}
const id = host.slice(1) as NodeId;
@@ -627,8 +830,7 @@ class Store {
openCommentary(note: NodeId) {
if (this.panes) {
const from = this.backHere();
this.openPane(this.paneAt, { kind: "node", id: note, from });
this.paneAt = this.trail.length - 1;
this.paneAt = this.openPane(this.paneAt, { kind: "node", id: note, from });
return this.setFocus({ node: note, grain: "node" });
}
this.colWiki = null;
@@ -703,8 +905,7 @@ class Store {
if (!id) return this.say(`The node this links to is gone${r.path?.length ? ` (it was “${r.path.join(" › ")}” in ${r.doc ?? "this document"})` : ""}, and nothing at its old place was found.`);
if (this.panes) {
const from = this.backHere();
this.openPane(this.paneAt, { kind: "node", id, from });
this.paneAt = this.trail.length - 1;
this.paneAt = this.openPane(this.paneAt, { kind: "node", id, from });
// Not reveal: that would unhoist, and the trail starts at the top node. A jump pane can show anything.
for (const a of ancestors(this.snap, id)) this.open.add(a);
this.setFocus({ node: id, grain: "node" });
@@ -716,8 +917,7 @@ class Store {
}
if (this.panes) {
const from = this.backHere();
this.openPane(this.paneAt, { kind: "wiki", title: r.title, lang: r.lang, from });
this.paneAt = this.trail.length - 1;
this.paneAt = this.openPane(this.paneAt, { kind: "wiki", title: r.title, lang: r.lang, from });
return this.setFocus(this.focus, { kind: "wiki", host: `p${this.paneAt}`, row: { t: "head" } });
}
this.openColWiki(r.title, r.lang, true);
@@ -948,17 +1148,20 @@ class Store {
}
private restoreView() {
const s = this.doc.snap();
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
const v = lsGet<{ open: NodeId[]; focus: Focus | null; hoist: NodeId | null; forks?: unknown; trail?: PaneRef[]; paneAt?: number }>(this.viewKey(), { open: [], focus: null, hoist: null });
this.open = new Set(v.open.filter((id) => s.nodes[id]));
this.hoist = v.hoist && s.nodes[v.hoist] ? v.hoist : null;
this.focus = v.focus && s.nodes[v.focus.node] ? v.focus : { node: this.top, grain: "node" };
this.trail = (v.trail ?? []).filter((p) => p.kind === "wiki" || s.nodes[p.id]);
// The tree of forks; a view saved before there were forks has only its trail, which loads as one branch.
this.tree = prune(restoreTree<PaneRef, Back>(v.forks, v.trail, isPaneRef), (p) => p.kind === "wiki" || !!s.nodes[p.id]);
this.paneAt = Math.min(v.paneAt ?? 0, Math.max(0, this.trail.length - 1));
this.aux = null;
this.repairView();
}
saveView() {
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, trail: this.trail.map((p) => ({ ...p, from: undefined })), paneAt: this.paneAt });
const bare = (p: PaneRef): PaneRef => ({ ...p, from: undefined });
// The trail too, for a build from before forks.
lsSet(this.viewKey(), { open: [...this.open], focus: this.focus, hoist: this.hoist, forks: saveTree(this.tree, bare), trail: this.trail.map(bare), paneAt: this.paneAt });
}
/** Keep focus on something that exists and is on screen. */
private repairView() {
@@ -1049,8 +1252,13 @@ class Store {
if (this.panes && s.nodes[found.node].kind === "section") this.open.add(found.node);
this.focus = { node: found.node, grain: "node" };
this.aux = null;
// A pane in another fork that shows it brings that fork onto the branch.
const at = this.trail.findIndex((p) => p.kind === "node" && p.id === found.node);
if (this.panes && at < 0) this.trail = this.panePath().map((id) => ({ kind: "node" as const, id }));
const fork = at < 0 && this.panes ? all(this.tree).find((x) => x.node.ref.kind === "node" && x.node.ref.id === found.node) : undefined;
if (fork && this.tree) {
this.setTree(select(this.tree, fork.node.id), false);
this.paneAt = fork.depth;
} else if (this.panes && at < 0) this.setTree(withBranch(this.tree, this.pathRefs(), sameRef), false);
else if (at >= 0) this.paneAt = at;
}
this.repairView();
@@ -1275,9 +1483,8 @@ class Store {
if (!this.panes) return;
this.syncTrail();
const p = this.trail[this.paneAt];
const next = this.trail[this.paneAt + 1];
if (open && p?.kind === "node" && this.snap.nodes[id]?.parent === p.id && this.snap.nodes[id].kind === "section") this.openPane(this.paneAt, { kind: "node", id });
else if (!open && next?.kind === "node" && next.id === id) this.trail = this.trail.slice(0, this.paneAt + 1);
else if (!open && this.tree) this.setTree(closeChild(this.tree, this.paneAt, { kind: "node", id }, sameRef));
}
setOpen(id: NodeId, open: boolean) {
@@ -1294,6 +1501,13 @@ class Store {
toggle(id = this.focus.node) {
if (id === this.top) return this.toggleFold(id);
if (this.listing(id)) return this.openDoc(id);
// In panes, a row whose pane is open as a fork that is not the focused one, or any row opened as a fork, opens (focuses) its pane rather than closing it.
if (this.panes) {
this.syncTrail();
const n = this.branchNodes[this.paneAt];
const k = n ? n.kids.findIndex((c) => c.ref.kind === "node" && c.ref.id === id) : -1;
if ((k >= 0 && k !== n.pick) || this.forking) return this.setOpen(id, true);
}
this.setOpen(id, !this.isOpen(id));
}
@@ -2250,11 +2464,11 @@ class Store {
held: { aux: Aux; keys: string[] } | null = null;
/** Whether a key on the aux focus is to wait for a held Tab. Any other key drops what was held. */
holdKey(k: string): boolean {
holdKey(k: string, shift = false): boolean {
const h = this.held;
if (!h) return false;
if ((k === "Enter" || k === "i") && sameAux(h.aux, this.aux)) {
h.keys.push(k);
h.keys.push(k === "Enter" && shift ? "S-Enter" : k);
return true;
}
if (k !== "Tab") this.held = null;
@@ -2271,7 +2485,7 @@ class Store {
this.held = null;
if (art?.state !== "ready") return;
for (const k of h.keys) {
if (k === "Enter") this.inArticleText ? this.enterArticle() : this.auxActivate();
if (k === "Enter" || k === "S-Enter") this.withFork(k === "S-Enter", () => (this.inArticleText ? this.enterArticle() : this.auxActivate()));
else if (k === "i") this.descend();
else this.auxTab(k === "Tab" ? 1 : -1);
}
@@ -2383,8 +2597,7 @@ class Store {
else this.reveal(focus.node);
if (this.panes) {
const from = this.backHere();
this.openPane(this.paneAt, { kind: "node", id: owner, from });
this.paneAt = this.trail.length - 1;
this.paneAt = this.openPane(this.paneAt, { kind: "node", id: owner, from });
} else this.colWiki = null;
this.setFocus(focus);
this.remember(true);