{order.map((c) => {
const items = cols.get(c)!;
@@ -700,6 +701,8 @@ interface Edge {
ey: number;
on: boolean;
lost: boolean;
+ /** The child's branch colour (forks.ts). */
+ hue?: number;
}
/** A font's descent, by its CSS font string: where its baseline sits above the bottom of an inline box. */
@@ -750,6 +753,8 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
const els = paneEls(el);
const colEls = [...el.children] as HTMLElement[];
const branch = new Set(store.branchNodes.map((n) => n.id));
+ // Coloured lines: a curve runs on into the rule under its pane's title (or its tab's), one line.
+ const ruled = store.settings.colors === "line";
const edges: Edge[] = [];
for (const x of store.panesPlaced) {
const parent = x.parent;
@@ -764,12 +769,17 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
// Where it arrives: just before the child's title, or its tab's; below a crowded column's foot, at the foot.
const cbox = ce.getBoundingClientRect();
let ey: number;
+ let ex = left + ARRIVE;
let lost = false;
- if (ce.hasAttribute("data-covered")) ey = cbox.top + TAB / 2;
+ if (ce.hasAttribute("data-covered")) ey = ruled ? cbox.top + TAB - 0.5 : cbox.top + TAB / 2;
else {
const scroll = ce.querySelector(".pane-scroll")!.getBoundingClientRect();
- const tr = ce.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.getBoundingClientRect();
+ const t = ce.querySelector(".pane-head h2, .top h1, .wiki-head h2");
+ const tr = t?.getBoundingClientRect();
ey = tr && tr.bottom > scroll.top + 4 ? Math.max(scroll.top + 6, tr.top + Math.min(tr.height, 32) / 2) : scroll.top + 14;
+ // The rule: a page title's own underline, a heading's under its head.
+ const rr = ruled && t ? (t.matches("h1") ? tr : t.parentElement?.getBoundingClientRect()) : undefined;
+ if (rr && rr.bottom > scroll.top + 4 && rr.bottom < scroll.bottom) (ey = rr.bottom - 0.5), (ex = Math.max(left + ARRIVE, rr.left));
}
if (ey > ccolBox.bottom - 4) {
ey = ccolBox.bottom - 4;
@@ -825,7 +835,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
}
}
const gutter = colEls.indexOf(ccol);
- edges.push({ from: parent.id, to: x.node.id, gutter, left: left - box.left, sx: sx - box.left, sy: sy - box.top, under: under && { x: under.x - box.left, y: under.y - box.top }, textRight: textRight - box.left, ex: left + ARRIVE - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost });
+ edges.push({ from: parent.id, to: x.node.id, gutter, left: left - box.left, sx: sx - box.left, sy: sy - box.top, under: under && { x: under.x - box.left, y: under.y - box.top }, textRight: textRight - box.left, ex: ex - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost, hue: x.node.hue });
}
// Lanes, gutter by gutter.
const lane = new Map();
@@ -842,7 +852,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
}
for (const g of [...lanesUsed.keys()]) if (!gutters.has(g)) lanesUsed.delete(g);
const fx = (n: number) => Math.round(n * 2) / 2;
- const out: { key: string; from: number; to: number; lane: number; cls: string; d: string }[] = [];
+ const out: { key: string; from: number; to: number; lane: number; cls: string; d: string; hue: string }[] = [];
edges.sort((a, b) => Number(a.on) - Number(b.on));
for (const e of edges) {
const i = lane.get(e)!;
@@ -865,7 +875,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
`C${fx(g)} ${fx(e.ey - sg * r2 * (1 - k))} ${fx(g + r2 - k * r2)} ${fx(e.ey)} ${fx(g + r2)} ${fx(e.ey)}` +
`H${fx(e.ex)}`;
}
- out.push({ key: `${e.from}>${e.to}`, from: e.from, to: e.to, lane: i, cls: `${e.on ? "on" : ""}${e.lost ? " lost" : ""}`, d });
+ out.push({ key: `${e.from}>${e.to}`, from: e.from, to: e.to, lane: i, cls: `${e.on ? "on" : ""}${e.lost ? " lost" : ""}`, d, hue: e.hue === undefined ? "" : String(e.hue) });
}
// Each curve keeps its element, changed only where it changed, so only what moved is painted again.
const had = new Map();
@@ -882,6 +892,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
if (p.getAttribute("d") !== c.d) p.setAttribute("d", c.d);
if (p.getAttribute("class") !== c.cls) p.setAttribute("class", c.cls);
if (p.dataset.lane !== String(c.lane)) p.dataset.lane = String(c.lane);
+ if ((p.dataset.hue ?? "") !== c.hue) c.hue ? (p.dataset.hue = c.hue) : delete p.dataset.hue;
// In drawing order: the focused branch's last, on top.
if (svg.children[k] !== p) svg.insertBefore(p, svg.children[k] ?? null);
});
diff --git a/src/ui/actions.ts b/src/ui/actions.ts
index 12d74af..40a7bae 100644
--- a/src/ui/actions.ts
+++ b/src/ui/actions.ts
@@ -229,6 +229,8 @@ export interface TopCtx {
auto: boolean;
speculate: boolean;
curves: boolean;
+ /** Where each fork's colour shows in the panes view (`/colors`). */
+ colors: "line" | "top" | "edge" | "off";
panes: boolean;
/** A document is open (its links can be looked for and reviewed). */
doc: boolean;
@@ -255,6 +257,7 @@ export function topEntries(c: TopCtx, act: Act): Entry[] {
setting("Reconcile after edits", "auto", c.auto),
setting("Write ahead while reading", "speculate", c.speculate),
c.panes && setting("Curves between panes", "curves", c.curves),
+ c.panes && { t: "choices", label: "Fork colours", options: (["line", "top", "edge", "off"] as const).map((v): Choice => ({ label: v, on: c.colors === v, run: () => act.command(`/colors ${v}`) })) },
SEP,
key(act, "Command line…", ":"),
key(act, "Keys and help", "?"),
diff --git a/src/ui/keys.ts b/src/ui/keys.ts
index f966925..eca4189 100644
--- a/src/ui/keys.ts
+++ b/src/ui/keys.ts
@@ -123,6 +123,7 @@ export const HELP: [string, [string, string][]][] = [
["/speculate on|off", "start writing the focused sentence's expansion early"],
["/view mode", "page layout: auto, column or panes; auto shows panes on windows 1600 px wide or more"],
["/curves on|off", "in panes: the faint curves from where each pane was opened to it"],
+ ["/colors line|top|edge|off", "in panes: each fork's own colour, on its curves and the rule under its panes' titles (line, the default), across their tops, down their left edges, or none"],
["/user name", "set the name on your commits"],
["/new title", "new blank document"],
["/open name", "open a document by title or id"],
diff --git a/src/ui/store.ts b/src/ui/store.ts
index 3617e7d..0f9036d 100644
--- a/src/ui/store.ts
+++ b/src/ui/store.ts
@@ -126,6 +126,9 @@ export interface Menu {
}
/** Page layout: one column with a margin, or panes side by side. Auto picks panes on wide windows. */
export type View = "auto" | "column" | "panes";
+/** Where a fork's colour shows in the panes view: along its curves and title rules, across its panes' tops, down their left edges, or nowhere. */
+export type Colors = "line" | "top" | "edge" | "off";
+const COLORS: Colors[] = ["line", "top", "edge", "off"];
/** The narrowest window, in CSS px, on which `auto` chooses panes. */
export const PANES_MIN_WIDTH = 1600;
@@ -231,7 +234,7 @@ class Store {
branchFrom: Commit | null = null;
/** A note being previewed on hover, and where to draw it. */
popup: { note: NodeId; x: number; top: number; bottom: number } | null = null;
- settings: { auto: boolean; speculate: boolean; view: View; autolink: AutoMode; curves: boolean } = { auto: true, speculate: false, view: "auto", autolink: "suggest", curves: true, ...lsGet("ie:settings", {}) };
+ settings: { auto: boolean; speculate: boolean; view: View; autolink: AutoMode; curves: boolean; colors: Colors } = { auto: true, speculate: false, view: "auto", autolink: "suggest", curves: true, colors: "line", ...lsGet("ie:settings", {}) };
/** Link discovery: scans after writes, suggestions, Related, the background job. */
links = new Linker({
doc: () => this.doc,
@@ -2179,6 +2182,7 @@ class Store {
auto: () => this.set("auto", arg !== "off"),
speculate: () => this.set("speculate", arg !== "off"),
curves: () => (this.set("curves", arg !== "off"), this.emit()),
+ colors: () => this.setColors(arg),
view: () => (["auto", "column", "panes"].includes(arg) ? this.setView(arg as View) : this.say(`/view auto, column or panes (now ${this.settings.view}, showing ${this.panes ? "panes" : "column"})`)),
resolve: () => this.resolveAll(),
new: () => (arg ? this.newDoc(arg) : this.openMenu("new")),
@@ -2964,6 +2968,15 @@ class Store {
this.say(arg === "on" ? "autolink on: sure links are made at once (u undoes); the rest are suggested" : arg === "suggest" ? "autolink suggest: links are only suggested; y takes one, S reviews them" : "autolink off: nothing is scanned automatically");
}
+ /** /colors: where each fork's colour shows in the panes view. */
+ setColors(arg: string) {
+ const c = COLORS.find((x) => x === arg);
+ if (!c) return this.say(`/colors line|top|edge|off (now ${this.settings.colors}): each fork's colour along its curves and title rules, across its panes' tops, down their left edges, or none`);
+ this.settings = { ...this.settings, colors: c };
+ lsSet("ie:settings", this.settings);
+ this.say(c === "off" ? "colors off: forks in plain ink" : `colors ${c}`);
+ }
+
/** /linkdoc, /linkall: scan in the background on the server; progress shows in the status line. */
async linkJob(scope: "doc" | "library", doc?: NodeId, quiet = false) {
const r = await this.links.startJob(scope, doc);
diff --git a/src/ui/style.css b/src/ui/style.css
index e27ca4b..546e5e5 100644
--- a/src/ui/style.css
+++ b/src/ui/style.css
@@ -450,6 +450,57 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
.curves path.on { stroke: var(--curve-on); }
.curves path.lost { stroke-dasharray: 1 3; }
+/*
+ * Branch colours (forks.ts): a fork's panes and curves share a colour, a plain trail keeps one, and
+ * the first trail has none. Seven hues at one OKLCH lightness and a low chroma, in an order that
+ * keeps neighbours apart for red-green and blue-yellow colour blindness too. The focused branch's at
+ * full strength, the others' fainter. Where it shows, by `/colors` (.panes[data-colors]): line, the
+ * curve and the rule under the pane's title (its tab's foot, a dash on its spine); top, a band
+ * across the pane's top; edge, a band down its left; off, nowhere. Never the pane's ground.
+ */
+:root {
+ --hue-0: oklch(60% 0.1 75);
+ --hue-1: oklch(60% 0.1 165);
+ --hue-2: oklch(60% 0.1 300);
+ --hue-3: oklch(60% 0.1 30);
+ --hue-4: oklch(60% 0.1 210);
+ --hue-5: oklch(60% 0.1 120);
+ --hue-6: oklch(60% 0.1 255);
+ --curve-ink: rgb(0 0 0 / 0.42);
+}
+@media (prefers-color-scheme: dark) {
+ :root {
+ --hue-0: oklch(74% 0.085 75);
+ --hue-1: oklch(74% 0.085 165);
+ --hue-2: oklch(74% 0.085 300);
+ --hue-3: oklch(74% 0.085 30);
+ --hue-4: oklch(74% 0.085 210);
+ --hue-5: oklch(74% 0.085 120);
+ --hue-6: oklch(74% 0.085 255);
+ --curve-ink: rgb(255 255 255 / 0.42);
+ }
+}
+[data-hue="0"] { --hue: var(--hue-0); }
+[data-hue="1"] { --hue: var(--hue-1); }
+[data-hue="2"] { --hue: var(--hue-2); }
+[data-hue="3"] { --hue: var(--hue-3); }
+[data-hue="4"] { --hue: var(--hue-4); }
+[data-hue="5"] { --hue: var(--hue-5); }
+[data-hue="6"] { --hue: var(--hue-6); }
+.panes:not([data-colors="off"]) :is(.pane, .curves path)[data-hue] { --branch: color-mix(in oklab, var(--hue) 70%, transparent); }
+.panes:not([data-colors="off"]) :is(.pane.on-branch, .curves path.on)[data-hue] { --branch: var(--hue); }
+.panes:not([data-colors="off"]) .curves path[data-hue] { stroke: var(--branch); }
+.panes:not([data-colors="off"]) .curves path.on:not([data-hue]) { stroke: var(--curve-ink); }
+/* line */
+[data-colors="line"] .pane[data-hue] > .pane-scroll > .pane-body > :is(.pane-head:not(.focused), .top:not(.focused) h1, .wiki:not(.embedded) > .wiki-head:not(.focused)) { border-bottom-color: var(--branch); }
+[data-colors="line"] .pane[data-hue] > .tabline { border-bottom-color: var(--branch); }
+[data-colors="line"] .pane[data-hue] > .spine::before { content: ""; position: absolute; top: 1.72rem; left: 50%; width: 0.9rem; margin-left: -0.45rem; height: 1px; background: var(--branch); }
+/* top: under the active pane's ink rule, above the focused branch's hairline */
+[data-colors="top"] .pane[data-hue] { background-image: linear-gradient(var(--branch), var(--branch)); background-size: 100% 2px; background-repeat: no-repeat; }
+[data-colors="top"] .pane[data-hue].on-branch:not(.active)::after { top: 2px; }
+/* edge */
+[data-colors="edge"] .pane[data-hue] { background-image: linear-gradient(var(--branch), var(--branch)); background-size: 2px 100%; background-position: 1px 0; background-repeat: no-repeat; }
+
/* A pane's head: a section heading, smaller than the page title the first pane keeps. */
.pane-head { display: flex; align-items: baseline; gap: 0.6em; margin: 0 0 0.85rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--faint); cursor: pointer; }
.pane-head.focused { border-bottom-color: var(--fg); }
diff --git a/tests/actions.test.ts b/tests/actions.test.ts
index bd149b1..0ba481e 100644
--- a/tests/actions.test.ts
+++ b/tests/actions.test.ts
@@ -21,7 +21,7 @@ const find = (es: Entry[], label: string) => items(es).find((i) => i.label === l
const node = (more: Partial = {}): NodeCtx => ({ title: "Training", text: "Training\n\nIt is trained.", note: false, locked: false, target: false, library: false, doc: false, generating: true, ...more });
const sel = (more: Partial = {}): SelCtx => ({ text: "a probability for each possible next piece", article: false, panes: false, ...more });
-const top = (more: Partial = {}): TopCtx => ({ view: "auto", autolink: "suggest", auto: true, speculate: false, curves: true, panes: false, doc: true, canRedo: false, ...more });
+const top = (more: Partial = {}): TopCtx => ({ view: "auto", autolink: "suggest", auto: true, speculate: false, curves: true, colors: "line", panes: false, doc: true, canRedo: false, ...more });
/** Every key the page's handler takes, read from keys.ts: an item's key must be one of them. */
const handled = new Set([...readFileSync(new URL("../src/ui/keys.ts", import.meta.url), "utf8").matchAll(/case "([^"]+)":/g)].map((m) => m[1]));
@@ -134,6 +134,10 @@ describe("actions", () => {
expect(calls).toEqual(["command /view panes", "command /auto off", "command /speculate on"]);
expect(labels(es)).not.toContain("Curves between panes");
expect(labels(topEntries(top({ panes: true }), act))).toContain("Curves between panes");
+ const colors = topEntries(top({ panes: true }), act).find((e) => e.t === "choices" && e.label === "Fork colours") as Extract;
+ expect(colors.options.map((o) => `${o.label}${o.on ? "*" : ""}`)).toEqual(["line*", "top", "edge", "off"]);
+ colors.options[3].run();
+ expect(calls.at(-1)).toBe("command /colors off");
expect(labels(topEntries(top({ doc: false }), act))).not.toContain("Review suggested links");
});