Panes: clicks, selection, tabs, peek and curves that keep to their content; Alt+h j k l between panes
- A click anywhere in a pane that is not text, a row or a link makes it the active pane; a click anywhere else, or Esc, clears a selection. - The page measures where each pane was opened from, so its column stands in that order. - A crowded column stacks the panes after the one looked at at its foot, a tab each, so every pane shows at least its tab; the curve into a tab becomes the tab's line where it meets it (no stub). - A pane cut off for any reason (covered, too small a share, past the foot) peeks out as tall as its text needs, without moving the panes around it; curves are redrawn on peek, on a pane's text changing size (ResizeObserver) and every frame while anything animates. - The curve joins the active pane's title rule too (the heavy rule alone marks it); a source out of sight in a pane that still shows is pointed at: dotted, turned at its end toward it; a curve leaves from a tab's foot only when its pane is folded to the tab. - The selection bar sits under a pane's tab, takes the room above or below the words, never covers them; a sticky tab's title is centred under the heavy rule; focus is kept clear of the tab. - Alt+h / Alt+l: the pane opened from (left) / one opened from this one (right); Alt+k / Alt+j (Alt+↑ ↓, [ ]): above / below in the column; from a node, a selection or an article; in the pane menu. - Browser tests (e2e/panes3.spec.ts) with a curve invariant (curveFaults) checked after peeks, scrolls, resizes, folds, a drag and an article arriving. 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
24a048a9f8
commit
0df51493cd
13 files changed
+727
-61
No files matched your search
+10
-3
@@ -13,6 +13,7 @@ import { PANES_MIN_WIDTH, store, type Aux, type WRow } from "./store";
|
||||
import { WikiPage, WikiView } from "./Wiki";
|
||||
import { Usage } from "./Usage";
|
||||
import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setPrompt, showBar, type Hint } from "./Mouse";
|
||||
import { press } from "./press";
|
||||
|
||||
function Page() {
|
||||
if (store.colWiki) return <WikiPage />;
|
||||
@@ -672,9 +673,15 @@ export function App() {
|
||||
const hit = at && store.sentenceAt(at.id, at.at);
|
||||
if (at && hit) return store.go(at.id, "sentence", hit), showBar();
|
||||
const node = target.closest<HTMLElement>("[data-node]");
|
||||
if (!node) return;
|
||||
// A pane's head makes that pane the active one.
|
||||
if (panes && paneEl && node.matches(".pane-head, .top")) store.paneAt = paneIndex;
|
||||
if (!node) {
|
||||
// Anywhere else in a pane (its margins, under its text, a list's gaps): that pane becomes the active one, and any selection goes.
|
||||
if (panes && paneEl) return store.land(paneIndex);
|
||||
// Anywhere else on the page: the selection goes.
|
||||
for (let i = 0; i < 3 && (store.focus.grain !== "node" || store.inArticleText); i++) press("Escape");
|
||||
return;
|
||||
}
|
||||
// Anything else of a node in a pane makes that pane the active one.
|
||||
if (panes && paneEl) store.paneAt = paneIndex;
|
||||
store.go(node.dataset.node as NodeId);
|
||||
};
|
||||
|
||||
|
||||
+13
-4
@@ -258,7 +258,7 @@ export const menuShown = () => !!shown;
|
||||
|
||||
const KEY_TEXT: Record<string, string> = { Enter: "⏎", Escape: "Esc", ArrowUp: "↑", ArrowDown: "↓" };
|
||||
/** How a key is written beside what it does. */
|
||||
export const keyText = (k: string) => KEY_TEXT[k] ?? k;
|
||||
export const keyText = (k: string) => KEY_TEXT[k] ?? (k.startsWith("A-") ? `Alt+${k.slice(2)}` : k);
|
||||
|
||||
/**
|
||||
* A menu: a small list of text, every item with its key. A popover by the pointer or the button it
|
||||
@@ -402,11 +402,20 @@ function placeBar(el: HTMLElement | null, shown = false) {
|
||||
const w = el.offsetWidth;
|
||||
const h = el.offsetHeight;
|
||||
const bar = document.querySelector(".docbar")?.getBoundingClientRect().bottom ?? 0;
|
||||
const below = first.top - h - 9 < bar + 4;
|
||||
// In the panes view it is set in its pane (so whatever covers the pane covers it), placed from the pane's box.
|
||||
const pane = el.parentElement?.classList.contains("pane") ? el.parentElement : null;
|
||||
const host = pane ? pane.getBoundingClientRect() : null;
|
||||
// The room it has: below the top bar, and in a pane below its tab when the tab shows (folded, or scrolled past its title) and above what covers its foot.
|
||||
const tabbed = pane && (pane.hasAttribute("data-scrolled") || pane.hasAttribute("data-covered"));
|
||||
const roof = Math.max(bar, host ? host.top + (tabbed ? 30 : 0) : 0) + 4;
|
||||
const next = pane?.parentElement?.classList.contains("crowded") ? (pane.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top : undefined;
|
||||
const floor = Math.min(window.innerHeight - 28, host?.bottom ?? Infinity, next ?? Infinity) - 4;
|
||||
// Over the words if it fits there, else under them; never on them.
|
||||
const above = first.top - 9 - roof;
|
||||
const under = floor - (last.bottom + 9);
|
||||
const below = above < h && (under >= h || under > above);
|
||||
const top = below ? last.bottom + 9 : first.top - h - 9;
|
||||
const mid = (left + right) / 2;
|
||||
// In the panes view it is set in its pane (so whatever covers the pane covers it), placed from the pane's box.
|
||||
const host = el.parentElement?.classList.contains("pane") ? el.parentElement.getBoundingClientRect() : null;
|
||||
const x = Math.round(Math.max((host?.left ?? 0) + 8, Math.min((host?.right ?? window.innerWidth) - w - 8, mid - w / 2)));
|
||||
el.classList.toggle("below", below);
|
||||
el.style.left = `${x - (host?.left ?? 0)}px`;
|
||||
|
||||
+131
-22
@@ -261,8 +261,10 @@ function nearestY(el: Element | null | false) {
|
||||
const r = el.getBoundingClientRect();
|
||||
const c = box.getBoundingClientRect();
|
||||
const pad = 28;
|
||||
if (r.top < c.top + pad) box.scrollTop += r.top - c.top - pad;
|
||||
else if (r.bottom > c.bottom - pad) box.scrollTop += Math.min(r.bottom - c.bottom + pad, r.top - c.top - pad);
|
||||
// Not under the tab a pane scrolled past its title shows at its top.
|
||||
const top = pad + TAB;
|
||||
if (r.top < c.top + top) box.scrollTop += r.top - c.top - top;
|
||||
else if (r.bottom > c.bottom - pad) box.scrollTop += Math.min(r.bottom - c.bottom + pad, r.top - c.top - top);
|
||||
}
|
||||
|
||||
const setAttr = (el: Element | undefined, name: string, on: boolean) => {
|
||||
@@ -360,7 +362,7 @@ export function Panes() {
|
||||
for (const c of colEls) {
|
||||
const ps = [...c.children].filter((p): p is HTMLElement => p.classList.contains("pane"));
|
||||
if (ps.length < 2) {
|
||||
for (const p of ps) if (p.style.height) (p.style.height = ""), (p.style.flex = ""), (p.style.top = "");
|
||||
for (const p of ps) if (p.style.height) (p.style.height = ""), (p.style.flex = ""), (p.style.top = ""), (p.style.bottom = "");
|
||||
c.classList.remove("crowded");
|
||||
unmark(ps);
|
||||
continue;
|
||||
@@ -382,6 +384,8 @@ export function Panes() {
|
||||
const crowded = need.reduce((s, x) => s + Math.min(x, PANE_MIN), 0) > h;
|
||||
let heights: number[];
|
||||
let tops: number[] = [];
|
||||
/** What the panes after each leave at the column's foot: a tab each, a pinned one its whole height. */
|
||||
let below: number[] = [];
|
||||
if (!crowded) heights = fill(h, need);
|
||||
else {
|
||||
// Each pane what its text needs, up to the column less a tab for each other pane; a pinned one, at most a third of it, but its least.
|
||||
@@ -389,6 +393,7 @@ export function Panes() {
|
||||
const free = h - pin.reduce((s, x) => s + x, 0) - (pinned.filter((x) => !x).length - 1) * TAB;
|
||||
heights = need.map((x, i) => (pinned[i] ? pin[i] : Math.min(x, Math.max(PANE_MIN, free))));
|
||||
tops = offsets(heights, pinned, TAB, h);
|
||||
below = heights.map((_, i) => heights.slice(i + 1).reduce((s, x, j) => s + (pinned[i + 1 + j] ? x : TAB), 0));
|
||||
}
|
||||
c.classList.toggle("crowded", crowded);
|
||||
// Only a crowded column is marked (measure): one that has room again is uncovered here.
|
||||
@@ -396,13 +401,19 @@ export function Panes() {
|
||||
ps.forEach((p, i) => {
|
||||
if (p.style.height !== `${heights[i]}px`) (p.style.height = `${heights[i]}px`), (p.style.flex = "none");
|
||||
});
|
||||
if (crowded) stick(ps, tops, DOWN);
|
||||
else for (const p of ps) p.style.top = "";
|
||||
if (crowded) {
|
||||
stick(ps, tops, DOWN);
|
||||
// Stuck at the foot as well, each a tab above those after it, so every pane shows at least its tab, above or below the one looked at.
|
||||
ps.forEach((p, i) => {
|
||||
const v = `${below[i] + (pinned[i] ? 0 : TAB - heights[i])}px`;
|
||||
if (p.style.bottom !== v) p.style.bottom = v;
|
||||
});
|
||||
} else for (const p of ps) (p.style.top = ""), (p.style.bottom = "");
|
||||
// The pane to show whole: on the focused branch, or the one last on it here.
|
||||
const here = tids.find((t) => onBranch.has(t)) ?? (tids.includes(lastIn.current.get(col)!) ? lastIn.current.get(col)! : tids[0]);
|
||||
const k = tids.indexOf(here);
|
||||
const st = starts(heights);
|
||||
const want = crowded ? reveal(c.scrollTop, h, st[k], heights[k], tops[k], st[st.length - 1] + heights[heights.length - 1] - h) : 0;
|
||||
const want = crowded ? reveal(c.scrollTop, h - below[k], st[k], heights[k], tops[k], st[st.length - 1] + heights[heights.length - 1] - h) : 0;
|
||||
// As the focus moves, the active pane's column scrolls at once and the others once the keys pause (each brings whole panes into view, which costs a frame's painting); any other change, at once.
|
||||
const sig = tids.map((t, i) => `${t}${pinned[i] ? "^" : ""}`).join();
|
||||
const same = laid.current.get(c) === sig;
|
||||
@@ -492,12 +503,42 @@ export function Panes() {
|
||||
});
|
||||
};
|
||||
|
||||
/** Where each newly opened pane came from in its parent, down the parent's text (its column's order goes by it). */
|
||||
const sources = () => {
|
||||
const el = strip.current;
|
||||
if (!el) return;
|
||||
const srcs = new Map<number, number>();
|
||||
const els = paneEls(el);
|
||||
for (const x of store.panesPlaced) {
|
||||
if (!x.parent || x.node.src !== undefined) continue;
|
||||
const pe = els.get(x.parent.id);
|
||||
const s = pe?.querySelector<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
const body = pe?.querySelector<HTMLElement>(".pane-body");
|
||||
const r = s?.getBoundingClientRect();
|
||||
if (r && body && r.height) srcs.set(x.node.id, Math.round(r.top - body.getBoundingClientRect().top));
|
||||
}
|
||||
if (srcs.size) store.setPaneSources(srcs);
|
||||
};
|
||||
|
||||
/** A pane's text growing or shrinking (an article arriving, notes opening) lays the columns out again and redraws the curves. */
|
||||
const bodies = useRef<ResizeObserver | null>(null);
|
||||
const watchedBodies = useRef(new WeakSet<Element>());
|
||||
|
||||
latest.current = layout;
|
||||
useLayoutEffect(() => {
|
||||
sources();
|
||||
layout();
|
||||
follow();
|
||||
measure();
|
||||
schedule();
|
||||
if (typeof ResizeObserver !== "undefined") {
|
||||
bodies.current ??= new ResizeObserver(() => {
|
||||
latest.current(true);
|
||||
measure();
|
||||
schedule();
|
||||
});
|
||||
for (const b of strip.current?.querySelectorAll(".pane-body") ?? []) if (!watchedBodies.current.has(b)) (watchedBodies.current.add(b), bodies.current.observe(b));
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -519,6 +560,23 @@ export function Panes() {
|
||||
};
|
||||
// Panes and crowded columns scroll on their own: their scroll events are caught on the way down.
|
||||
wrap.addEventListener("scroll", onScroll, { passive: true, capture: true });
|
||||
// While anything animates, the curves are drawn every frame, so they follow it.
|
||||
let moving = 0;
|
||||
const tick = () => {
|
||||
if (!moving) return;
|
||||
curves(strip.current, svg.current);
|
||||
requestAnimationFrame(tick);
|
||||
};
|
||||
const onRun = () => {
|
||||
if (!moving++) requestAnimationFrame(tick);
|
||||
};
|
||||
const onEnd = () => {
|
||||
moving = Math.max(0, moving - 1);
|
||||
if (!moving) schedule();
|
||||
};
|
||||
wrap.addEventListener("transitionrun", onRun);
|
||||
wrap.addEventListener("transitionend", onEnd);
|
||||
wrap.addEventListener("transitioncancel", onEnd);
|
||||
// The strip changes size with the window and when the history panel opens or closes.
|
||||
const sizes = new ResizeObserver(onResize);
|
||||
sizes.observe(el);
|
||||
@@ -538,28 +596,46 @@ export function Panes() {
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const lower = (it: HTMLElement) => {
|
||||
it.removeAttribute("data-peek");
|
||||
it.removeAttribute("data-peek-h");
|
||||
it.style.removeProperty("--peek-h");
|
||||
it.style.removeProperty("--peek-extra");
|
||||
it.style.transform = "";
|
||||
};
|
||||
function hide() {
|
||||
if (!peeked.length) return;
|
||||
for (const it of peeked) lower(it);
|
||||
peeked = [];
|
||||
peekedFor = null;
|
||||
schedule();
|
||||
}
|
||||
function unpeek() {
|
||||
clearTimeout(timer);
|
||||
pending = null;
|
||||
hide();
|
||||
}
|
||||
/** What must come out for a pane to show whole: its column, if later columns cover it; the pane, if later panes in a crowded column do, or the column's foot cuts it. */
|
||||
/**
|
||||
* How tall a pane would be shown whole (what its text needs, up to its column's height), if it is
|
||||
* cut off now (0 if not): shown shorter than that for any reason, covered by the pane after it, given
|
||||
* too small a share of its column, or running past the column's foot.
|
||||
*/
|
||||
const cutOff = (pane: HTMLElement): number => {
|
||||
const col = pane.parentElement as HTMLElement;
|
||||
const r = pane.getBoundingClientRect();
|
||||
const c = col.getBoundingClientRect();
|
||||
const next = col.classList.contains("crowded") ? ((pane.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity) : Infinity;
|
||||
const shown = Math.max(0, Math.min(r.bottom, c.bottom, next) - Math.max(r.top, c.top));
|
||||
const sc = pane.querySelector<HTMLElement>(".pane-scroll")!;
|
||||
const cs = getComputedStyle(sc);
|
||||
const need = needs.current.get(Number(pane.dataset.tid)) ?? pane.querySelector<HTMLElement>(".pane-body")!.offsetHeight + parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + 1;
|
||||
const full = Math.min(Math.ceil(need), Math.floor(c.height));
|
||||
return shown < full - 2 ? full : 0;
|
||||
};
|
||||
/** What must come out for a pane to show whole: its column, if later columns cover it; the pane, if it is cut off down its column. */
|
||||
const peekable = (pane: HTMLElement): HTMLElement[] => {
|
||||
const col = pane.parentElement as HTMLElement;
|
||||
const out: HTMLElement[] = [];
|
||||
if (col.hasAttribute("data-covered") || (col.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over")) out.push(col);
|
||||
if (col.classList.contains("crowded")) {
|
||||
const r = pane.getBoundingClientRect();
|
||||
const c = col.getBoundingClientRect();
|
||||
if (pane.hasAttribute("data-covered") || (pane.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over") || r.bottom > c.bottom + 1) out.push(pane);
|
||||
}
|
||||
if (col.children.length > 1 && cutOff(pane)) out.push(pane);
|
||||
return out;
|
||||
};
|
||||
const peek = (pane: HTMLElement, its: HTMLElement[]) => {
|
||||
@@ -569,12 +645,21 @@ export function Panes() {
|
||||
peeked.push(it);
|
||||
it.setAttribute("data-peek", "");
|
||||
if (it === pane) {
|
||||
// As tall as it needs, without moving the panes around it (the extra height takes no room), then lifted into the column.
|
||||
const full = cutOff(it);
|
||||
if (full) {
|
||||
const h = it.offsetHeight;
|
||||
it.style.setProperty("--peek-h", `${full}px`);
|
||||
it.style.setProperty("--peek-extra", `${Math.max(0, full - h)}px`);
|
||||
it.setAttribute("data-peek-h", "");
|
||||
}
|
||||
const r = it.getBoundingClientRect();
|
||||
const c = (it.parentElement as HTMLElement).getBoundingClientRect();
|
||||
const dy = Math.max(c.top - r.top, Math.min(0, c.bottom - r.bottom));
|
||||
if (dy) it.style.transform = `translateY(${Math.round(dy)}px)`;
|
||||
}
|
||||
}
|
||||
schedule();
|
||||
};
|
||||
const onMove = (e: PointerEvent) => {
|
||||
if (e.pointerType !== "mouse" || e.buttons || drag) return;
|
||||
@@ -694,6 +779,10 @@ export function Panes() {
|
||||
clearTimeout(later.current);
|
||||
clearTimeout(timer);
|
||||
wrap.removeEventListener("scroll", onScroll, { capture: true });
|
||||
wrap.removeEventListener("transitionrun", onRun);
|
||||
wrap.removeEventListener("transitionend", onEnd);
|
||||
wrap.removeEventListener("transitioncancel", onEnd);
|
||||
bodies.current?.disconnect();
|
||||
sizes.disconnect();
|
||||
el.removeEventListener("pointermove", onMove);
|
||||
el.removeEventListener("pointerleave", unpeek);
|
||||
@@ -755,6 +844,8 @@ interface Edge {
|
||||
sy: number;
|
||||
/** For words: the right end of their underline, which a short step joins to the lead-out. */
|
||||
under?: { x: number; y: number };
|
||||
/** For a source out of sight in its pane: the point on the pane's edge, over it, where the curve ends turned toward it. */
|
||||
hint?: { x: number; y: number };
|
||||
textRight: number;
|
||||
ex: number;
|
||||
ey: number;
|
||||
@@ -862,7 +953,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
const t = ce.querySelector<HTMLElement>(".pane-head h2, .top h1, .wiki-head h2");
|
||||
const tr = t?.getBoundingClientRect();
|
||||
ey = folded ? cbox.top + TAB / 2 : tr && tr.bottom > scroll.top + 4 ? Math.max(scroll.top + 6, tr.top + Math.min(tr.height, 32) / 2) : scroll.top + 14;
|
||||
// The rule: under the pane's own head (a section's, a page's title, an article's), not an article's set under a node; and not while that head holds the focus (its rule is then the text's ink).
|
||||
// The rule: under the pane's own head (a section's, a page's title, an article's), not an article's set under a node; the focused head's too (the heavy rule on top marks the active pane).
|
||||
const head = ruled ? ce.querySelector<HTMLElement>(HEADS) : null;
|
||||
const ruleEl = head?.matches(".top") ? head.querySelector<HTMLElement>("h1") : head;
|
||||
const rs = (ruleEl ?? ce.querySelector<HTMLElement>(".pane-head, .top h1, .wiki-head"))?.getBoundingClientRect();
|
||||
@@ -870,7 +961,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
folded = true;
|
||||
ey = cbox.top + TAB / 2;
|
||||
}
|
||||
const rr = ruleEl && !head!.classList.contains("focused") ? rs : undefined;
|
||||
const rr = ruleEl ? rs : undefined;
|
||||
const below = ccol.classList.contains("crowded") ? ((ce.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity) : Infinity;
|
||||
if (rr && rr.bottom > top + 4 && rr.bottom < Math.min(scroll.bottom, below) && rr.left < shownRight) {
|
||||
ey = level(rr.bottom - 0.5);
|
||||
@@ -882,11 +973,13 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
// Folded or scrolled so far that its title's rule does not show: into its tab's foot.
|
||||
if (folded && !rule && ruled) {
|
||||
ey = level(cbox.top + TAB - 0.5);
|
||||
rule = { x0: cbox.left, x1: Math.round(Math.min(cbox.right - 1, nextCol) * dpr) / dpr };
|
||||
// From where the curve meets it, on under the tab: the curve becomes the tab's line.
|
||||
rule = { x0: ex, x1: Math.round(Math.min(cbox.right - 1, nextCol) * dpr) / dpr };
|
||||
rules.set(x.node.id, "tab");
|
||||
tabbed.add(x.node.id);
|
||||
}
|
||||
if (ey > ccolBox.bottom - 4) {
|
||||
// Below the column's foot (every pane leaves at least its tab there now, so this is only a pane still being laid out).
|
||||
if (ey > ccolBox.bottom) {
|
||||
ey = ccolBox.bottom - 4;
|
||||
lost = true;
|
||||
}
|
||||
@@ -896,11 +989,12 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
let sx = textRight;
|
||||
let sy: number;
|
||||
let under: { x: number; y: number } | undefined;
|
||||
let hint: { x: number; y: number } | undefined;
|
||||
// What of the pane shows: its own scroll box (below its tab, if folded), less what the pane after it in a crowded column covers, down to the column's foot.
|
||||
const pfolded = pe.hasAttribute("data-covered");
|
||||
const pscroll = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const nextTop = pcol.classList.contains("crowded") ? (pe.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top : undefined;
|
||||
const sc = { top: pfolded ? Math.max(pscroll.top, pbox.top + TAB) : pscroll.top, bottom: Math.min(pscroll.bottom, nextTop ?? Infinity, pcol.getBoundingClientRect().bottom) };
|
||||
const sc = { top: pfolded || pe.hasAttribute("data-scrolled") ? Math.max(pscroll.top, pbox.top + TAB) : pscroll.top, bottom: Math.min(pscroll.bottom, nextTop ?? Infinity, pcol.getBoundingClientRect().bottom) };
|
||||
const cands = pe.hasAttribute("data-buried") ? [] : pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
let src: HTMLElement | undefined;
|
||||
for (const c of cands) {
|
||||
@@ -910,7 +1004,8 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfolded && !src) {
|
||||
// Folded to its tab (no more than a line or so of it showing) with its source out of sight.
|
||||
if (pfolded && !src && sc.bottom - sc.top < 48) {
|
||||
// Folded with its source out of sight: out of the right end of its tab's foot, carrying that line on (its foot drawn here too, so they join exactly).
|
||||
const footRight = Math.round(Math.min(pbox.right - 1, left) * dpr) / dpr;
|
||||
sy = level(pbox.top + TAB - 0.5);
|
||||
@@ -941,8 +1036,18 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
if (sy < sc.top + 2 || sy > sc.bottom - 2 || sx > textRight + 1) {
|
||||
lost = true;
|
||||
under = undefined;
|
||||
sx = textRight;
|
||||
sy = Math.max(sc.top + 2, Math.min(sc.bottom - 2, sy));
|
||||
const dir = sy > sc.bottom - 2 ? 1 : sy < sc.top + 2 ? -1 : 0;
|
||||
if (dir && sc.bottom - sc.top > 40) {
|
||||
// Out of sight above or below in its pane: the dotted curve turns at its end toward it, ending at the pane's edge over where it is.
|
||||
const hx = Math.max(pbox.left + 40, Math.min(r.right, textRight - 16));
|
||||
const edge = dir > 0 ? sc.bottom - 1 : sc.top + 1;
|
||||
sy = level(edge - dir * 14);
|
||||
hint = { x: hx, y: edge };
|
||||
sx = hx + 6;
|
||||
} else {
|
||||
sx = textRight;
|
||||
sy = Math.max(sc.top + 2, Math.min(sc.bottom - 2, sy));
|
||||
}
|
||||
}
|
||||
sy = level(sy);
|
||||
if (under) under.y = level(under.y);
|
||||
@@ -955,7 +1060,7 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
tabbed.delete(x.node.id);
|
||||
}
|
||||
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: ex - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost, hue: x.node.hue, rule: rule && { x0: rule.x0 - box.left, x1: rule.x1 - box.left } });
|
||||
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 }, hint: hint && { x: hint.x - box.left, y: hint.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, rule: rule && { x0: rule.x0 - box.left, x1: rule.x1 - box.left } });
|
||||
}
|
||||
// Lanes, gutter by gutter.
|
||||
const lane = new Map<Edge, number>();
|
||||
@@ -981,7 +1086,11 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
const g = e.left + LANE_LAST - i * LANE_PITCH;
|
||||
const dy = e.ey - e.sy;
|
||||
let d: string;
|
||||
const join = e.under ? `M${fx(e.under.x)} ${fx(e.under.y)}C${fx((e.under.x + e.sx) / 2)} ${fx(e.under.y)} ${fx((e.under.x + e.sx) / 2)} ${fx(e.sy)} ${fx(e.sx)} ${fx(e.sy)}` : `M${fx(e.sx)} ${fx(e.sy)}`;
|
||||
const join = e.under
|
||||
? `M${fx(e.under.x)} ${fx(e.under.y)}C${fx((e.under.x + e.sx) / 2)} ${fx(e.under.y)} ${fx((e.under.x + e.sx) / 2)} ${fx(e.sy)} ${fx(e.sx)} ${fx(e.sy)}`
|
||||
: e.hint
|
||||
? `M${fx(e.hint.x)} ${fx(e.hint.y)}V${fx(e.sy + Math.sign(e.hint.y - e.sy) * 6)}Q${fx(e.hint.x)} ${fx(e.sy)} ${fx(e.sx)} ${fx(e.sy)}`
|
||||
: `M${fx(e.sx)} ${fx(e.sy)}`;
|
||||
if (Math.abs(dy) < 1.5) d = `${join}H${fx(e.ex)}`;
|
||||
else {
|
||||
// A lead-out to the lane, a quarter turn, the lane, a quarter turn into the title. Each turn's radius grows by a pitch per lane outwards, so a bundle turning together stays parallel; a turn never starts inside the text.
|
||||
|
||||
@@ -206,6 +206,16 @@ export function paneEntries(c: PaneCtx, act: Act): Entry[] {
|
||||
return tidy([
|
||||
...own,
|
||||
SEP,
|
||||
{
|
||||
t: "choices",
|
||||
label: "Go to the pane",
|
||||
options: [
|
||||
{ label: "left", key: "A-h", run: () => act.press("A-h") },
|
||||
{ label: "right", key: "A-l", run: () => act.press("A-l") },
|
||||
{ label: "above", key: "A-k", run: () => act.press("A-k") },
|
||||
{ label: "below", key: "A-j", run: () => act.press("A-j") },
|
||||
],
|
||||
},
|
||||
key(act, "Pin this pane", "P", { checked: c.pinned, sub: "it stays when what opened it closes" }),
|
||||
key(act, "Close this pane", "q", { sub: "with what was opened from it" }),
|
||||
key(act, "Show as one column", "v"),
|
||||
|
||||
+23
-1
@@ -19,6 +19,8 @@ export const HELP: [string, [string, string][]][] = [
|
||||
["P", "in panes: pin or unpin the active pane (or its pin, top right). A pinned pane stays where it is when a pane it came from closes, is never replaced by a Shift open, and is never covered, in its column or along the strip"],
|
||||
["Enter l", "in panes: open into the next column, beside what is open there (so does a click, and a Ctrl-, Cmd- or middle click); on something open already, focus it"],
|
||||
["Shift+Enter", "in panes: open in place of the focused branch's pane in the next column (so does a Shift-click)"],
|
||||
["Alt+h Alt+l", "in panes: the pane this one was opened from (left) / one opened from it (right): the one opened from the focused row or link if it is open, else the one last visited; from a node, a selection or an article alike. Left then right comes back"],
|
||||
["Alt+k Alt+j", "in panes: the pane above / below in the same column, across forks (Alt+↑ ↓ and [ ] too)"],
|
||||
["[ ]", "in panes: the pane above / below in the same column (back where you were in it, or at its head); at the top or bottom nothing moves. A crowded column stacks its panes as the strip stacks columns, covered to a tab; resting the mouse on a covered pane peeks it out; its grip or tab drags it up or down. A faint curve runs from where each pane was opened to its title"], ],
|
||||
],
|
||||
[
|
||||
@@ -154,8 +156,28 @@ interface KeyHooks {
|
||||
verify(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Between panes, whatever the focus (a node, a sentence, an article): Alt with h j k l, or with ↑ ↓.
|
||||
* By the key's place on the keyboard (e.code), so a layout or Option producing another letter still works.
|
||||
*/
|
||||
const PANE_KEYS: Record<string, () => void> = {
|
||||
KeyH: () => store.paneSide(-1),
|
||||
KeyL: () => store.paneSide(1),
|
||||
KeyK: () => store.focusFork(-1),
|
||||
KeyJ: () => store.focusFork(1),
|
||||
ArrowUp: () => store.focusFork(-1),
|
||||
ArrowDown: () => store.focusFork(1),
|
||||
};
|
||||
|
||||
export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
if (!store.ready || isTyping(e) || e.metaKey || e.ctrlKey || e.altKey) return;
|
||||
if (!store.ready || isTyping(e) || e.metaKey || e.ctrlKey) return;
|
||||
if (e.altKey) {
|
||||
const go = !e.shiftKey && store.mode === "normal" ? PANE_KEYS[e.code] : undefined;
|
||||
if (!go) return;
|
||||
e.preventDefault();
|
||||
store.t0 = { what: `A-${e.code}`, at: e.timeStamp };
|
||||
return go();
|
||||
}
|
||||
const k = e.key;
|
||||
const done = () => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -5,5 +5,10 @@
|
||||
* and no action has a second implementation.
|
||||
*/
|
||||
export function press(key: string, shift = false) {
|
||||
// "A-h": Alt with that key, by its place on the keyboard as the keymap reads it.
|
||||
if (key.startsWith("A-")) {
|
||||
const k = key.slice(2);
|
||||
return void window.dispatchEvent(new KeyboardEvent("keydown", { key: k, code: k.length === 1 ? `Key${k.toUpperCase()}` : k, altKey: true, shiftKey: shift, bubbles: true, cancelable: true }));
|
||||
}
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", { key, shiftKey: shift, bubbles: true, cancelable: true }));
|
||||
}
|
||||
+54
-5
@@ -36,7 +36,7 @@ import { remoteLLM } from "./remote";
|
||||
import { Session } from "./session";
|
||||
import { refreshAfterCalls } from "./usage";
|
||||
import { Linker, type AutoMode, type JobState, type LinkRow, type Status, type Sugg } from "./linker";
|
||||
import { all, besideInColumn, close as closeIn, columns as columnsOf, reorder, focus as focusIn, focused, open as openIn, path, pin as pinIn, prune, restore as restoreForest, rooted, save as saveTree, updateIn, withBranch, type Forest, type Placed, type Tree } from "./forks";
|
||||
import { all, besideInColumn, close as closeIn, columns as columnsOf, reorder, focus as focusIn, focused, open as openIn, path, pin as pinIn, prune, restore as restoreForest, rooted, save as saveTree, setSources, updateIn, withBranch, type Forest, type Placed, type Tree } from "./forks";
|
||||
import { stripMarks, type Mark } from "../core/marks";
|
||||
import { SEED_SLUG } from "../core/seed";
|
||||
|
||||
@@ -672,8 +672,8 @@ class Store {
|
||||
}
|
||||
|
||||
/**
|
||||
* [ and ]: the pane above or below the active one in its column (whichever fork or tree it is in).
|
||||
* The focus goes back where it was when that pane was last left this way, or to the pane's head.
|
||||
* [ and ] (Alt+k, Alt+j): the pane above or below the active one in its column (whichever fork or
|
||||
* tree it is in). The focus goes back where it was when that pane was last left, or to its head.
|
||||
*/
|
||||
focusFork(delta: number) {
|
||||
if (!this.panes) return this.say("Forks are side by side in the panes view (v); one column shows one page.");
|
||||
@@ -684,14 +684,54 @@ class Store {
|
||||
const alone = here && besideInColumn(this.forest, here.id, -delta) === null;
|
||||
return this.say(alone ? "This is the only pane in its column. Shift+Enter, or a Shift- or Ctrl-click, opens a fork below the pane to the right." : `No pane ${delta < 0 ? "above" : "below"} this one in its column.`);
|
||||
}
|
||||
this.goPane(next);
|
||||
}
|
||||
|
||||
/** Make a pane the active one, from the active one: the focus goes back where it was when that pane was last left, or to its head. */
|
||||
private goPane(id: number) {
|
||||
const here = this.branchNodes[this.paneAt];
|
||||
const seen = this.backHere();
|
||||
this.setForest(focusIn(updateIn(this.forest, here.id, (n) => ({ ...n, seen })), next));
|
||||
const hit = this.forkNode(next)!;
|
||||
this.setForest(focusIn(here ? updateIn(this.forest, here.id, (n) => ({ ...n, seen })) : this.forest, id));
|
||||
const hit = this.forkNode(id)!;
|
||||
const b = hit.node.seen;
|
||||
if (b && b.pane === hit.depth && this.snap.nodes[b.focus.node] && (b.aux ? this.auxValid(b.aux) : this.holds(b.pane, b.focus))) return this.restore(b);
|
||||
this.land(hit.depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alt+h and Alt+l: the pane the active one was opened from (left), or one opened from it (right):
|
||||
* the one opened from the focused row or link if it is open, else the one last visited there.
|
||||
* Left then right comes back to the same pane.
|
||||
*/
|
||||
paneSide(delta: number) {
|
||||
if (!this.panes) return this.say("Panes are side by side in the panes view (v).");
|
||||
this.syncTrail();
|
||||
const here = this.branchNodes[this.paneAt];
|
||||
if (!here) return;
|
||||
if (delta < 0) {
|
||||
const parent = this.branchNodes[this.paneAt - 1];
|
||||
if (!parent) return this.say(this.paneAt === 0 && this.forest.at > 0 ? "This pane's source has closed; nothing to its left." : "Nothing to the left of this pane.");
|
||||
return this.goPane(parent.id);
|
||||
}
|
||||
if (!here.kids.length) return this.say("Nothing opened from this pane yet: Enter or l on a row or link opens it to the right.");
|
||||
const f = this.focus;
|
||||
const a = this.aux;
|
||||
const key =
|
||||
a?.kind === "wiki" && a.row.t === "sec" ? refKey({ kind: "wiki", title: this.wikiHost(a.host)?.title ?? "", lang: "", sec: a.row.id }) : !a && f.grain === "node" ? refKey({ kind: "node", id: f.node }) : this.selectionTargetKey();
|
||||
const k = here.kids.find((c) => refKey(c.ref) === key) ?? here.kids[here.pick];
|
||||
this.goPane(k.id);
|
||||
}
|
||||
|
||||
/** What the selected words link to, as a pane's key (refKey), if they link. */
|
||||
private selectionTargetKey(): string | undefined {
|
||||
const f = this.focus;
|
||||
if (f.grain === "node" || !f.range) return undefined;
|
||||
const n = this.snap.nodes[f.node];
|
||||
const note = n?.children.map((c) => this.snap.nodes[c]).find((c) => c?.kind === "note" && c.ref && c.anchors[0] && c.anchors[0].start <= f.range![0] && c.anchors[0].end >= f.range![1]);
|
||||
if (!note?.ref) return undefined;
|
||||
return this.targetKey(note.ref);
|
||||
}
|
||||
|
||||
/** Whether the focus is a row whose pane is open next to it (so that pane is the one the reader is looking at). */
|
||||
showingFocus(): boolean {
|
||||
const next = this.trail[this.paneAt + 1];
|
||||
@@ -738,6 +778,15 @@ class Store {
|
||||
}
|
||||
|
||||
/** A pane dragged up or down its column, to just above another (or to the bottom). */
|
||||
/** The page has measured where panes were opened from in their parents: their columns stand in that order (forks.ts columns). */
|
||||
setPaneSources(srcs: Map<number, number>) {
|
||||
const f = setSources(this.forest, srcs);
|
||||
if (f === this.forest) return;
|
||||
this.setForest(f);
|
||||
this.saveView();
|
||||
this.emit();
|
||||
}
|
||||
|
||||
reorderPane(id: number, before: number | null) {
|
||||
const f = reorder(this.forest, id, before);
|
||||
if (f === this.forest) return;
|
||||
|
||||
+12
-7
@@ -419,6 +419,9 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.col.crowded > .pane[data-covered] > .tabline { opacity: 1; pointer-events: auto; }
|
||||
/* A pane scrolled past its own title shows its tab at its top as well, over its text (Panes.tsx watchHead). */
|
||||
.pane[data-scrolled] > .tabline { opacity: 1; pointer-events: auto; }
|
||||
/* Its title centred between the rule across the pane's top (heavy on the active pane) and its foot. */
|
||||
.pane.active > .tabline { padding-top: 3px; }
|
||||
.pane.on-branch:not(.active) > .tabline { padding-top: 1px; }
|
||||
.pane[data-scrolled] > .pane-ctl { top: 2px; }
|
||||
.pane[data-scrolled] > .grip { display: none; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
@@ -430,6 +433,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
|
||||
/* Peeking: a covered pane or column, the mouse resting on it, raised over its neighbours whole. */
|
||||
.col[data-peek], .pane[data-peek] { z-index: 6; box-shadow: 0 3px 18px 0 var(--shade); }
|
||||
/* A pane peeking down its column is shown as tall as its text needs; the extra height takes no room, so nothing around it moves. */
|
||||
.pane[data-peek-h] { height: var(--peek-h) !important; margin-bottom: calc(-1 * var(--peek-extra, 0px)); }
|
||||
.col[data-peek] .spine, .col.crowded > .pane[data-peek] > .tabline { opacity: 0; pointer-events: none; }
|
||||
/* The wheel over what peeks scrolls its text, not the column under it. */
|
||||
.col[data-peek] .pane-scroll, .pane[data-peek] > .pane-scroll { overscroll-behavior: contain; }
|
||||
@@ -517,13 +522,13 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
* rule itself (Panes.tsx curves; the pane's own is left out, data-ruled), so the two are one stroke.
|
||||
* Where no curve lands (curves off, a covered source), the pane's own rule takes its colour.
|
||||
*/
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .pane-head:not(.focused),
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .top:not(.focused) h1,
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head:not(.focused),
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .pane-head,
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .top h1,
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head,
|
||||
:where([data-colors="line"] .pane[data-hue]) > .tabline { border-bottom-color: var(--hue-faint); }
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .pane-head:not(.focused),
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .top:not(.focused) h1,
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head:not(.focused),
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .pane-head,
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .top h1,
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head,
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .tabline { border-bottom-color: var(--hue); }
|
||||
.pane[data-ruled~="head"] > .pane-scroll > .pane-body > .pane-head,
|
||||
.pane[data-ruled~="head"] > .pane-scroll > .pane-body > .top h1,
|
||||
@@ -817,7 +822,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
}
|
||||
.selbar.below::after { bottom: auto; top: -5px; transform: rotate(225deg); }
|
||||
/* In the panes view the bar is set in its pane, so a pane or column over that pane covers it too. */
|
||||
.pane > .selbar { position: absolute; }
|
||||
.pane > .selbar { position: absolute; z-index: 1; }
|
||||
|
||||
/* The ⋯ by a row, a pane's head, a page's head or a note: invisible until wanted, never moving the text. */
|
||||
.more {
|
||||
|
||||
Reference in new issue
Block a user