Panes by column: a forest of panes, curves between them, close, pin and an active rule
The tree of forks becomes a forest: a pinned pane stays open when a pane it was opened from closes, as an orphan in its own column. Close takes a pane and what was opened from it, pinned panes excepted; pin and unpin; [ and ] move to the pane above or below in a column. The panes view is laid out by column: column d holds every pane at depth d and divides its own height among them, a short pane taking only what its text needs; when they do not fit, all but the focused branch's pane (and pinned ones) fold into one-line tabs. A faint curve runs from the words, row or link each pane was opened from to its title, the focused branch's in a stronger ink; curves through one gutter take lanes side by side, ordered to cross least. Every pane has the same hairline right and bottom. The active pane has a heavy rule across its top, the rest of the focused branch a hairline. Each pane has a pin and a x at its top right (the x also on its spine); q closes the active pane, whatever it shows (it used to close a whole fork from wherever the fork began, which closed the node an article was opened from); P pins it. /curves off hides the curves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
2f8ca98207
commit
3298cc430c
20 files changed
+1822
-783
No files matched your search
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Lanes for the panes view's curves (Panes.tsx): where several curves run down one gutter, each gets
|
||||
* a lane of its own, side by side like a ribbon cable, in the order that crosses least.
|
||||
*/
|
||||
|
||||
/** Lanes in a gutter: vertical runs this far apart, from just inside the column's edge to just short of its titles. */
|
||||
export const LANE_PITCH = 4;
|
||||
export const LANE_FIRST = 5;
|
||||
export const LANE_LAST = 29;
|
||||
export const LANES = Math.floor((LANE_LAST - LANE_FIRST) / LANE_PITCH) + 1;
|
||||
|
||||
/**
|
||||
* How many times curves in one gutter cross, for an order of lanes (rightmost first): a lead-out
|
||||
* comes in from the left at its source's height, crossing the lanes left of its own still running
|
||||
* there; an arrival goes right at its title's height, crossing the lanes right of its own.
|
||||
*/
|
||||
export function crossings(order: { sy: number; ey: number }[]): number {
|
||||
const runs = (c: { sy: number; ey: number }, y: number) => y > Math.min(c.sy, c.ey) && y < Math.max(c.sy, c.ey);
|
||||
let n = 0;
|
||||
for (let i = 0; i < order.length; i++)
|
||||
for (let j = i + 1; j < order.length; j++) {
|
||||
// order[i] is right of order[j].
|
||||
if (runs(order[j], order[i].sy)) n++;
|
||||
if (runs(order[i], order[j].ey)) n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* The order of a gutter's lanes, rightmost first, so that curves cross as little as they can: the
|
||||
* curve with the shortest way to go takes the lane nearest the panes, and the rest outwards. Starting from the order last used, with new curves put
|
||||
* where that rule puts them, a curve is moved to another lane only while that removes crossings, so a
|
||||
* scroll or an open elsewhere does not reshuffle the bundle.
|
||||
*/
|
||||
export function laneOrder<T extends { key: string; sy: number; ey: number }>(edges: T[], last: string[] = []): T[] {
|
||||
const rule = [...edges].sort((a, b) => {
|
||||
const da = a.ey >= a.sy ? a.ey - a.sy : a.sy - a.ey;
|
||||
const db = b.ey >= b.sy ? b.ey - b.sy : b.sy - b.ey;
|
||||
return da - db;
|
||||
});
|
||||
const byKey = new Map(edges.map((e) => [e.key, e]));
|
||||
const order = last.flatMap((k) => byKey.get(k) ?? []);
|
||||
for (const e of rule) {
|
||||
if (order.includes(e)) continue;
|
||||
const r = rule.indexOf(e);
|
||||
const at = order.findIndex((o) => rule.indexOf(o) > r);
|
||||
order.splice(at < 0 ? order.length : at, 0, e);
|
||||
}
|
||||
// Move one curve to another lane while that removes crossings (a few curves per gutter: cheap).
|
||||
let best = crossings(order);
|
||||
for (let pass = 0, better = true; better && pass < order.length; pass++) {
|
||||
better = false;
|
||||
for (let i = 0; i < order.length && best; i++)
|
||||
for (let j = 0; j < order.length; j++) {
|
||||
if (j === i) continue;
|
||||
const moved = order.slice();
|
||||
moved.splice(j, 0, ...moved.splice(i, 1));
|
||||
const n = crossings(moved);
|
||||
if (n < best) {
|
||||
order.splice(0, order.length, ...moved);
|
||||
best = n;
|
||||
better = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user