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
@@ -103,24 +103,35 @@ Press `?` for every key. The short version:
|
||||
open already focuses it; a second `Enter` on an open row keeps it (closing is `q`'s or the x's).
|
||||
A document chosen in the menu, or by `/open`, opens in place of the one open. Moving back left
|
||||
with `h` closes nothing.
|
||||
- **Columns.** Column d holds every pane at depth d, top to bottom, and divides its own height among
|
||||
them, a short pane taking only what its text needs. When they do not all fit, the column stacks
|
||||
them the way the strip stacks columns: each pane stuck a tab below the one before, the pane on the
|
||||
focused branch shown whole and the others slid under it, partly and at the limit down to a
|
||||
one-line tab, just as earlier columns slide under later ones down to a spine. A pane scrolled
|
||||
past its own title shows the same tab at its top, over its text. Mouse resting on a covered pane,
|
||||
tab or spine: after a moment it peeks out over its neighbours, its column across and the pane down
|
||||
its column at once, and stays out while the pointer is on it (the wheel scrolls it); a click makes
|
||||
it the active pane. A pane's grip (the band above its title, by the pin and x, shown when pointed at) or
|
||||
its tab drags it up or down its column; Esc cancels; the column keeps that order. `[` and `]` go to
|
||||
the pane above and below in the column, back where you were in it; at the top or bottom they stay.
|
||||
`h` and `l` move along the focused branch.
|
||||
- **Columns.** Column d holds every pane at depth d, top to bottom, in the order of what they were
|
||||
opened from: by where their parents stand, then by where in the parent each was opened from, so a
|
||||
pane opened from higher up stands higher (and curves cross as little as they can). A column divides
|
||||
its own height among its panes, a short pane taking only what its text needs. When they do not all
|
||||
fit, the column stacks them the way the strip stacks columns: the pane on the focused branch shown
|
||||
whole, those before it stuck a tab apart above it and those after it a tab apart at the column's
|
||||
foot, partly covered and at the limit down to a one-line tab, so every pane shows at least its tab.
|
||||
A pane scrolled past its own title shows the same tab at its top, over its text. 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. Mouse resting on a pane that is cut off for any reason (covered across
|
||||
or down, too small a share of its column, past its foot): after a moment it peeks out whole over
|
||||
its neighbours, its column across and the pane down its column, as tall as its text needs, and
|
||||
stays out while the pointer is on it (the wheel scrolls it); a click makes it the active pane. A
|
||||
pane's grip (the band above its title, by the pin and x, shown when pointed at) or its tab drags
|
||||
it up or down its column; Esc cancels; the column keeps that order, and a pane opened later goes in
|
||||
just after the one before it in its own order.
|
||||
- **Between panes, by keys.** `Alt+h` goes to the pane this one was opened from, `Alt+l` to one
|
||||
opened from it (the one opened from the focused row or link, if it is open, else the one last
|
||||
visited there), `Alt+k` and `Alt+j` (or `Alt+↑` `Alt+↓`, or `[` `]`) to the pane above and below
|
||||
in the column, across forks; the same from a node, a selection or an article, back where you were
|
||||
in each pane, and left then right comes back. Plain `h` and `l` still move along the focused branch.
|
||||
The pane menu (`⋯`) offers the same.
|
||||
- **Curves.** A curve runs from the words, row or link each pane was opened from (joined to their
|
||||
underline) into the rule under the pane's title, and draws that rule, so the two are one hairline
|
||||
on device pixels; the focused branch's is drawn stronger. Where the title does not show (the pane
|
||||
folded to its tab, or scrolled past it), the curve runs into the tab's foot instead; out of a
|
||||
folded pane whose source is out of sight, it leaves from the end of that pane's tab foot. A source
|
||||
scrolled out of a pane it is still in is held at the pane's edge and the curve dotted. Curves down
|
||||
scrolled or covered out of sight in a pane that still shows is pointed at: the curve is dotted
|
||||
and ends turned toward it, at the pane's edge over where it is. Curves down
|
||||
one gutter run side by side, ordered to cross as little as they can. `/curves off` hides them.
|
||||
- **Fork colours.** Each fork has a colour of its own, quiet and the same lightness for all: a
|
||||
pane opened as the first from its pane goes on in that pane's colour, any other starts the next
|
||||
|
||||
+7
-6
@@ -171,15 +171,15 @@ test("a click, a Ctrl- and a middle click open beside; a Shift-click in place; a
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Borrowed from Gwern", kids[0]]);
|
||||
expect(await focusedTitle(page)).toBe(kids[0]);
|
||||
await expect(page.locator(".pane.active .pane-head h2")).toHaveText(kids[0]);
|
||||
// The first pane's rows too: beside, in the next column; and a click on a row already open keeps it.
|
||||
// The first pane's rows too: beside, in the next column (above, as its row is above); and a click on a row already open keeps it.
|
||||
await row("Display forms").click();
|
||||
expect(await columns(page)).toEqual([["Infinispand"], ["Borrowed from Gwern", "Display forms"], kids.slice(0, 3)]);
|
||||
await expect.poll(() => columns(page)).toEqual([["Infinispand"], ["Display forms", "Borrowed from Gwern"], kids.slice(0, 3)]);
|
||||
await row("Display forms").click();
|
||||
expect((await columns(page))[1]).toEqual(["Borrowed from Gwern", "Display forms"]);
|
||||
expect((await columns(page))[1]).toEqual(["Display forms", "Borrowed from Gwern"]);
|
||||
// A Shift-click opens in place of the focused one (Display forms), and selects no text on the way.
|
||||
await row("Editing and regeneration").click({ modifiers: ["Shift"] });
|
||||
expect(await trail(page)).toEqual(["Infinispand", "Editing and regeneration"]);
|
||||
expect((await columns(page))[1]).toEqual(["Borrowed from Gwern", "Editing and regeneration"]);
|
||||
await expect.poll(async () => (await columns(page))[1]).toEqual(["Editing and regeneration", "Borrowed from Gwern"]);
|
||||
expect(await page.evaluate(() => window.getSelection()?.isCollapsed ?? true)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -197,14 +197,15 @@ test("a link and an article's link open beside by default, in place with Shift;
|
||||
await keys(page, "h");
|
||||
await tabTo(page, "lambda calculus");
|
||||
await keys(page, "Shift+Enter");
|
||||
expect((await columns(page))[3]).toEqual(["Fixed-point combinator", "“lambda calculus”"]); // a note on the words, with the article beneath
|
||||
// A note on the words, with the article beneath; above, as its words come first in the text.
|
||||
await expect.poll(async () => (await columns(page))[3]).toEqual(["“lambda calculus”", "Fixed-point combinator"]);
|
||||
// In an article: a click opens beside, a Shift-click in place.
|
||||
const art = pane(page, "Fixed-point combinator");
|
||||
await art.locator('.wiki-text a[data-wiki="Haskell Curry"]').click();
|
||||
await art.locator('.wiki-text a[data-wiki="Recursion (computer science)"]').click();
|
||||
expect((await columns(page))[4]).toEqual(["Haskell Curry", "Recursion (computer science)"]);
|
||||
await art.locator('.wiki-text a[data-wiki="Lambda calculus"]').first().click({ modifiers: ["Shift"] });
|
||||
expect((await columns(page))[4]).toEqual(["Haskell Curry", "Lambda calculus"]);
|
||||
await expect.poll(async () => (await columns(page))[4]).toEqual(["Lambda calculus", "Haskell Curry"]);
|
||||
// Twenty opens in a row: each a pane of its own, the column stacked, the keys still quick.
|
||||
await open(page);
|
||||
await page.evaluate(() => ((globalThis as any).__ie.samples.length = 0));
|
||||
|
||||
@@ -157,3 +157,70 @@ export function pixels(buf: Buffer): { w: number; h: number; px: (x: number, y:
|
||||
}
|
||||
return { w, h, px: (x, y) => [out[y * stride + x * bpp], out[y * stride + x * bpp + 1], out[y * stride + x * bpp + 2]] };
|
||||
}
|
||||
|
||||
/**
|
||||
* The curves' invariant, measured from the page: every curve drawn starts at what its pane was
|
||||
* opened from (the row, the words, or a link: within a few pixels of it), or, when that is out of
|
||||
* sight, on its pane's edge over it (dotted), or at the end of its folded pane's tab foot; and ends
|
||||
* in its pane's landing line: the rule under its title, along to the rule's end, or its tab's foot,
|
||||
* or just before its title. Returns what fails, as text (empty when all hold).
|
||||
*/
|
||||
export const curveFaults = (page: Page) =>
|
||||
page.evaluate(() => {
|
||||
const ie = (globalThis as any).__ie;
|
||||
const refKey = (p: any) => (p.kind === "node" ? `n:${p.id}` : `w:${p.title}${p.sec !== undefined ? `#${p.sec}` : ""}`);
|
||||
const kidClass = (key: string) => {
|
||||
let h = 5381;
|
||||
for (let i = 0; i < key.length; i++) h = ((h * 33) ^ key.charCodeAt(i)) >>> 0;
|
||||
return `k${h.toString(36)}`;
|
||||
};
|
||||
const TAB = 30;
|
||||
const faults: string[] = [];
|
||||
const svg = document.querySelector<SVGSVGElement>(".curves")!.getBoundingClientRect();
|
||||
const box = { left: Math.round(svg.left), top: Math.round(svg.top) };
|
||||
const placed = new Map<number, any>(ie.panesPlaced.map((x: any) => [x.node.id, x]));
|
||||
for (const p of document.querySelectorAll<SVGPathElement>(".curves path:not(.foot)")) {
|
||||
const to = Number(p.dataset.to);
|
||||
const from = Number(p.dataset.from);
|
||||
const ce = document.querySelector<HTMLElement>(`.pane[data-tid="${to}"]`);
|
||||
const pe = document.querySelector<HTMLElement>(`.pane[data-tid="${from}"]`);
|
||||
const x = placed.get(to);
|
||||
if (!ce || !pe || !x) {
|
||||
faults.push(`${from}>${to}: no pane`);
|
||||
continue;
|
||||
}
|
||||
const a0 = p.getPointAtLength(0);
|
||||
const b0 = p.getPointAtLength(p.getTotalLength());
|
||||
const a = { x: a0.x + box.left, y: a0.y + box.top };
|
||||
const b = { x: b0.x + box.left, y: b0.y + box.top };
|
||||
const lost = p.classList.contains("lost");
|
||||
const name = `${from}>${to} ${ce.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim()}`;
|
||||
const cr = ce.getBoundingClientRect();
|
||||
const col = ce.parentElement!.getBoundingClientRect();
|
||||
const nextCol = (ce.parentElement!.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().left ?? Infinity;
|
||||
// The end.
|
||||
const ruled = ce.dataset.ruled ?? "";
|
||||
if (ruled.includes("head")) {
|
||||
const head = ce.querySelector<HTMLElement>(":scope > .pane-scroll > .pane-body > .pane-head, :scope > .pane-scroll > .pane-body > .top h1, :scope > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head")!;
|
||||
const r = head.getBoundingClientRect();
|
||||
if (Math.abs(b.y - (r.bottom - 0.5)) > 1.2) faults.push(`${name}: ends at y ${b.y}, its title's rule at ${r.bottom - 0.5}`);
|
||||
if (Math.abs(b.x - Math.min(r.right, nextCol, cr.right)) > 1.6) faults.push(`${name}: ends at x ${b.x}, its rule's end at ${Math.min(r.right, nextCol)}`);
|
||||
} else if (ruled.includes("tab") && !lost) {
|
||||
if (Math.abs(b.y - (cr.top + TAB - 0.5)) > 1.2) faults.push(`${name}: ends at y ${b.y}, its tab's foot at ${cr.top + TAB - 0.5}`);
|
||||
} else if (!lost) {
|
||||
if (b.x < col.left - 1 || b.x > col.left + 60 || b.y < cr.top - 1 || b.y > Math.min(cr.bottom, col.bottom) + 1) faults.push(`${name}: ends at ${b.x},${b.y}, outside its pane's head (${cr.top}..${cr.bottom})`);
|
||||
}
|
||||
// The start.
|
||||
const pr = pe.getBoundingClientRect();
|
||||
if (a.x < pr.left - 1 || a.x > Math.max(pr.right, pr.right) + 1) faults.push(`${name}: starts at x ${a.x}, outside its source pane ${pr.left}..${pr.right}`);
|
||||
const footStart = Math.abs(a.y - (pr.top + TAB - 0.5)) <= 1.2 && Math.abs(a.x - Math.min(pr.right - 1, col.left)) <= 2;
|
||||
if (lost || footStart) continue;
|
||||
const cands = [...pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`)];
|
||||
const near = cands.some((c) => {
|
||||
const el = c.matches("li") ? (c.querySelector<HTMLElement>(":scope > .row") ?? c) : c;
|
||||
return [...el.getClientRects()].some((r) => a.x >= r.left - 2 && a.x <= r.right + 10 && a.y >= r.top - 4 && a.y <= r.bottom + 6);
|
||||
});
|
||||
if (!near) faults.push(`${name}: starts at ${a.x},${a.y}, not at its source (${cands.length} candidates)`);
|
||||
}
|
||||
return faults;
|
||||
});
|
||||
@@ -0,0 +1,368 @@
|
||||
/**
|
||||
* The panes view, round three: a click anywhere in a pane makes it active and anywhere clears a
|
||||
* selection; a column's panes stand in the order of their sources; every pane in a crowded column
|
||||
* shows at least its tab, above or below; a pane cut off for any reason peeks out whole; the curves
|
||||
* keep to their sources and landing lines through every kind of layout change (curveFaults); the
|
||||
* selection bar keeps clear of a tab; a dotted curve turns toward its source; Alt with h j k l moves
|
||||
* between panes. Same build, mock model and mock Wikipedia as the others.
|
||||
*/
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { autoLayout, curveFaults, keys, seedLinks, settle, state } from "./helpers";
|
||||
|
||||
const TAB = 30;
|
||||
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
|
||||
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
async function still(page: Page) {
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
new Promise((r) => {
|
||||
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
|
||||
const x = at();
|
||||
setTimeout(() => r(at() === x), 250);
|
||||
}),
|
||||
);
|
||||
await frames(page);
|
||||
}
|
||||
async function open(page: Page, inPane: string, text: string, sel = ".row") {
|
||||
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
|
||||
await still(page);
|
||||
}
|
||||
async function library(page: Page) {
|
||||
await autoLayout(page);
|
||||
await page.goto("/");
|
||||
await page.waitForSelector(".strip .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
}
|
||||
const activeTitle = (page: Page) => page.locator(".pane.active").evaluate((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? "");
|
||||
const colTitles = (page: Page, i: number) =>
|
||||
page.evaluate((i) => [...document.querySelectorAll(".strip > .col")[i].querySelectorAll(":scope > .pane")].map((p) => p.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim() ?? ""), i);
|
||||
const noFaults = async (page: Page, when: string) => {
|
||||
await still(page);
|
||||
expect(await curveFaults(page), when).toEqual([]);
|
||||
};
|
||||
|
||||
test.use({ viewport: { width: 1920, height: 1080 }, colorScheme: "dark" });
|
||||
test.describe.configure({ mode: "serial" });
|
||||
test.beforeAll(async ({ request }) => {
|
||||
await seedLinks(request);
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
await context.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
});
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
test("a column's panes stand in the order of their sources: opened from a row higher up, a pane stands higher", async ({ page }) => {
|
||||
await library(page);
|
||||
await open(page, "Library", "Octopus minds");
|
||||
await open(page, "Library", "Infinispand");
|
||||
await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Octopus minds"]);
|
||||
await open(page, "Library", "Fixed points");
|
||||
await expect.poll(() => colTitles(page, 1)).toEqual(["Infinispand", "Fixed points", "Octopus minds"]);
|
||||
// Kept with the view.
|
||||
await page.reload();
|
||||
await page.waitForSelector(".strip .pane");
|
||||
expect(await colTitles(page, 1)).toEqual(["Infinispand", "Fixed points", "Octopus minds"]);
|
||||
await noFaults(page, "after a reload");
|
||||
});
|
||||
|
||||
test("a click anywhere in a pane that is not text, a row or a link makes that pane the active one; anywhere at all clears a selection, and so does Esc", async ({ page }) => {
|
||||
await library(page);
|
||||
await open(page, "Library", "Fixed points");
|
||||
await open(page, "Fixed points", "The idea itself");
|
||||
for (const t of ["Library", "Fixed points", "The idea itself", "Library", "The idea itself", "Fixed points"]) {
|
||||
const p = pane(page, t);
|
||||
const b = (await p.boundingBox())!;
|
||||
// A grid of points over the pane; those that fall on nothing that acts are clicked.
|
||||
const spots = await p.evaluate((el) => {
|
||||
const r = el.getBoundingClientRect();
|
||||
const out: { x: number; y: number }[] = [];
|
||||
for (let i = 1; i < 12; i++)
|
||||
for (let j = 1; j < 12; j++) {
|
||||
const x = r.left + (r.width * i) / 12;
|
||||
const y = r.top + (r.height * j) / 12;
|
||||
const hit = document.elementFromPoint(x, y) as HTMLElement | null;
|
||||
if (!hit || !el.contains(hit) || hit.closest("[data-node], [data-row], a, button, [role=button], [data-more], [data-linking], [data-related], [data-target], [data-wrow], .pane-ctl, .grip, .tabline, .spine, [data-wtext], .lnk, .anchor")) continue;
|
||||
out.push({ x, y });
|
||||
}
|
||||
return out;
|
||||
});
|
||||
expect(spots.length, t).toBeGreaterThan(3);
|
||||
for (const s of spots.slice(0, 6)) {
|
||||
// Away first, so each click is a change.
|
||||
const other = t === "Library" ? "Fixed points" : "Library";
|
||||
await pane(page, other).locator(".pane-head h2, .top h1").first().dispatchEvent("click");
|
||||
await page.mouse.click(s.x, s.y);
|
||||
await expect.poll(() => activeTitle(page), `${t} at ${Math.round(s.x - b.x)},${Math.round(s.y - b.y)}`).toBe(t);
|
||||
}
|
||||
}
|
||||
// A selection goes on a click elsewhere: in another pane's margin, on the top bar, and with Esc.
|
||||
const bar = page.locator(".selbar");
|
||||
const select = async () => {
|
||||
await pane(page, "The idea itself").locator(".pane-body .para").first().click({ position: { x: 40, y: 10 } });
|
||||
await expect(bar).toBeVisible();
|
||||
};
|
||||
await select();
|
||||
const lib = (await pane(page, "Library").boundingBox())!;
|
||||
await page.mouse.click(lib.x + lib.width - 12, lib.y + lib.height - 20);
|
||||
await expect(bar).toHaveCount(0);
|
||||
expect(await activeTitle(page)).toBe("Library");
|
||||
expect(await state(page, (s) => s.focus.grain)).toBe("node");
|
||||
await select();
|
||||
const top = (await page.locator(".docbar").boundingBox())!;
|
||||
await page.mouse.click(top.x + top.width / 2, top.y + top.height / 2);
|
||||
await expect(bar).toHaveCount(0);
|
||||
await select();
|
||||
await keys(page, "Escape");
|
||||
await expect(bar).toHaveCount(0);
|
||||
expect(await state(page, (s) => s.focus.grain)).toBe("node");
|
||||
});
|
||||
|
||||
test("every pane of a crowded column shows at least its tab, above or below the one looked at; tabs line up with the active rule; curves stay on their sources and lines", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 700 });
|
||||
await library(page);
|
||||
for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points", "What a proof is"]) await open(page, "Library", t);
|
||||
// The one looked at near the top: those below it stack at the column's foot.
|
||||
await pane(page, "Infinispand").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
for (const first of ["Infinispand", "What a proof is"]) {
|
||||
if (first !== "Infinispand") {
|
||||
await pane(page, first).locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
}
|
||||
const shown = await page.evaluate(() => {
|
||||
const col = [...document.querySelectorAll<HTMLElement>(".strip > .col")][1];
|
||||
const c = col.getBoundingClientRect();
|
||||
const ps = [...col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||
return ps.map((p, i) => {
|
||||
const r = p.getBoundingClientRect();
|
||||
const next = ps[i + 1]?.getBoundingClientRect().top ?? Infinity;
|
||||
return { t: p.querySelector(".top h1")?.textContent?.trim(), shown: Math.min(next, c.bottom) - Math.max(r.top, c.top) };
|
||||
});
|
||||
});
|
||||
for (const s of shown) expect(s.shown, `${first} looked at: ${s.t}`).toBeGreaterThanOrEqual(TAB - 1);
|
||||
await noFaults(page, `${first} looked at`);
|
||||
}
|
||||
// A folded tab's title is centred between the rule over the pane and the tab's foot; on the active pane, under its heavy rule.
|
||||
const centred = await page.evaluate(() =>
|
||||
[...document.querySelectorAll<HTMLElement>(".strip .pane[data-covered], .strip .pane[data-scrolled]")].map((p) => {
|
||||
const r = p.getBoundingClientRect();
|
||||
const t = p.querySelector<HTMLElement>(".tabline .tabtitle")!.getBoundingClientRect();
|
||||
const rule = parseFloat(getComputedStyle(p, "::after").height) || 0;
|
||||
return { active: p.classList.contains("active"), off: Math.abs((t.top + t.bottom) / 2 - (r.top + rule + r.top + 29) / 2) };
|
||||
}),
|
||||
);
|
||||
expect(centred.length).toBeGreaterThan(0);
|
||||
for (const c of centred) expect(c.off).toBeLessThanOrEqual(1.5);
|
||||
// The curve becomes a tab's line where it meets it: no stub of it before the meeting.
|
||||
const stubs = await page.evaluate(() =>
|
||||
[...document.querySelectorAll<SVGPathElement>(".curves path:not(.foot)")].filter((p) => {
|
||||
const pe = document.querySelector<HTMLElement>(`.pane[data-tid="${p.dataset.to}"]`);
|
||||
return pe?.dataset.ruled?.includes("tab") && (p.getAttribute("d")!.match(/M/g) ?? []).length > 1;
|
||||
}).length,
|
||||
);
|
||||
expect(stubs).toBe(0);
|
||||
});
|
||||
|
||||
test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 700 });
|
||||
await library(page);
|
||||
for (const t of ["Octopus minds", "Infinispand", "The tides", "Fixed points"]) await open(page, "Library", t);
|
||||
/** Hover each pane of the documents' column that is cut off, and check it comes out whole, and the curves with it. */
|
||||
const sweep = async (label: string, across: boolean) => {
|
||||
const col = page.locator(".strip > .col").nth(1);
|
||||
const n = await col.locator(":scope > .pane").count();
|
||||
let peeked = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const p = col.locator(":scope > .pane").nth(i);
|
||||
const info = await p.evaluate((el) => {
|
||||
const c = el.parentElement!.getBoundingClientRect();
|
||||
const r = el.getBoundingClientRect();
|
||||
const next = (el.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity;
|
||||
const sc = getComputedStyle(el.querySelector(".pane-scroll")!);
|
||||
const need = el.querySelector<HTMLElement>(".pane-body")!.offsetHeight + parseFloat(sc.paddingTop) + parseFloat(sc.paddingBottom);
|
||||
const top = Math.max(r.top, c.top);
|
||||
const bottom = Math.min(r.bottom, next, c.bottom);
|
||||
// A point on what shows of it, clear of the pin and x.
|
||||
return { cut: bottom - top < Math.min(need, c.height) - 4, x: Math.max(r.left, c.left) + 14, y: top + Math.min(14, (bottom - top) / 2), colH: c.height, need, title: el.querySelector(".top h1")?.textContent?.trim() };
|
||||
});
|
||||
if (!info.cut && !across) continue;
|
||||
await page.mouse.move(info.x, info.y);
|
||||
await page.waitForTimeout(450);
|
||||
if (!info.cut) {
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
continue;
|
||||
}
|
||||
peeked++;
|
||||
await expect(p, `${label}: ${info.title}`).toHaveAttribute("data-peek", "");
|
||||
const whole = await p.evaluate((el) => {
|
||||
const c = el.parentElement!.getBoundingClientRect();
|
||||
const r = el.getBoundingClientRect();
|
||||
const hit = document.elementFromPoint(Math.max(r.left, c.left) + 60, (Math.max(r.top, c.top) + Math.min(r.bottom, c.bottom)) / 2);
|
||||
return { h: r.height, inside: r.top >= c.top - 1 && r.bottom <= c.bottom + 1, top: !!hit && el.contains(hit) };
|
||||
});
|
||||
expect(whole.h, `${label}: ${info.title} height`).toBeGreaterThanOrEqual(Math.min(info.need, info.colH) - 3);
|
||||
expect(whole.inside, `${label}: ${info.title} inside its column`).toBe(true);
|
||||
expect(whole.top, `${label}: ${info.title} on top`).toBe(true);
|
||||
expect(await curveFaults(page), `${label}: ${info.title} peeking`).toEqual([]);
|
||||
await page.mouse.move(1910, 690);
|
||||
await expect(p).not.toHaveAttribute("data-peek", "");
|
||||
await noFaults(page, `${label}: ${info.title} back`);
|
||||
}
|
||||
return peeked;
|
||||
};
|
||||
// Covered from below (the one looked at near the top) and from above (near the foot).
|
||||
await pane(page, "Infinispand").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
expect(await sweep("top looked at", false)).toBeGreaterThan(0);
|
||||
await pane(page, "Octopus minds").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
expect(await sweep("foot looked at", false)).toBeGreaterThan(0);
|
||||
// Beside a pinned pane.
|
||||
await pane(page, "The tides").locator(".top h1").dispatchEvent("click");
|
||||
await keys(page, "P");
|
||||
await still(page);
|
||||
expect(await sweep("beside a pinned one", false)).toBeGreaterThan(0);
|
||||
await keys(page, "P");
|
||||
// Its column covered too: deeper panes push it under; a cut-off pane comes out across and down at once.
|
||||
await open(page, "Fixed points", "The idea itself");
|
||||
await open(page, "The idea itself", "Three questions");
|
||||
await still(page);
|
||||
const col = page.locator(".strip > .col").nth(1);
|
||||
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
||||
expect(await sweep("column covered", true)).toBeGreaterThan(0);
|
||||
|
||||
// By its share of a column that is not crowded: a tall window, two documents, one longer than its share.
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k)));
|
||||
await library(page);
|
||||
await open(page, "Library", "Infinispand");
|
||||
await open(page, "Library", "Octopus minds");
|
||||
await pane(page, "Octopus minds").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
|
||||
expect(await sweep("by share", false)).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("the curves keep to their sources and landing lines through every kind of layout change: scrolls, a resize, folding, a drag, an article arriving, a sticky tab", async ({ page }) => {
|
||||
await library(page);
|
||||
for (const t of ["Infinispand", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "Fixed points", "Recursion without names");
|
||||
await noFaults(page, "opened");
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
await noFaults(page, "article arrived");
|
||||
// Scrolls: a pane's text, the strip.
|
||||
await pane(page, "Recursion without names").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 120));
|
||||
await noFaults(page, "a pane scrolled (sticky tab)");
|
||||
await pane(page, "Recursion without names").locator(".pane-scroll").evaluate((el) => (el.scrollTop = 0));
|
||||
await noFaults(page, "scrolled back");
|
||||
await page.locator(".strip").evaluate((el) => (el.scrollLeft = Math.max(0, el.scrollLeft - 300)));
|
||||
await noFaults(page, "the strip scrolled");
|
||||
// A resize that folds the documents' column, and back.
|
||||
await page.setViewportSize({ width: 1920, height: 520 });
|
||||
await noFaults(page, "folded");
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
await noFaults(page, "resized");
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await noFaults(page, "unfolded");
|
||||
// A drag down the documents' column.
|
||||
await page.evaluate(() => {
|
||||
const ie = (globalThis as any).__ie;
|
||||
const col = ie.paneColumns.get(1);
|
||||
ie.reorderPane(col[0].node.id, null);
|
||||
});
|
||||
await noFaults(page, "dragged");
|
||||
});
|
||||
|
||||
test("the selection bar keeps clear of a pane's tab and of the words it is about", async ({ page }) => {
|
||||
await library(page);
|
||||
await open(page, "Library", "Fixed points");
|
||||
const p = pane(page, "Fixed points");
|
||||
await p.locator(".pane-scroll").evaluate((el) => (el.scrollTop = 160));
|
||||
await expect(p).toHaveAttribute("data-scrolled", "");
|
||||
// A sentence just under the tab.
|
||||
const at = await p.evaluate((el) => {
|
||||
const top = el.getBoundingClientRect().top + 30;
|
||||
const para = [...el.querySelectorAll<HTMLElement>(".pane-body .para")].find((x) => x.getBoundingClientRect().bottom > top + 12);
|
||||
const r = para!.getBoundingClientRect();
|
||||
return { x: r.left + 30, y: Math.max(r.top, top) + 8 };
|
||||
});
|
||||
await page.mouse.click(at.x, at.y);
|
||||
const bar = page.locator(".selbar");
|
||||
await expect(bar).toBeVisible();
|
||||
const b = (await bar.boundingBox())!;
|
||||
const tab = (await p.locator(".tabline").boundingBox())!;
|
||||
expect(b.y).toBeGreaterThanOrEqual(tab.y + tab.height - 1);
|
||||
const words = await page.evaluate(() => [...document.querySelectorAll(".sel")].flatMap((s) => [...s.getClientRects()].map((r) => ({ top: r.top, bottom: r.bottom, left: r.left, right: r.right }))));
|
||||
for (const w of words) expect(b.y >= w.bottom - 1 || b.y + b.height <= w.top + 1, "the bar covers the words").toBe(true);
|
||||
});
|
||||
|
||||
test("a dotted curve to a source out of sight in its pane turns, at its end, toward where the source is", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 560 });
|
||||
await library(page);
|
||||
await open(page, "Library", "A mind made of text");
|
||||
const lib = pane(page, "Library").locator(".pane-scroll");
|
||||
const lead = async () =>
|
||||
page.evaluate(() => {
|
||||
const p = [...document.querySelectorAll<SVGPathElement>(".curves path:not(.foot)")].find((x) => x.classList.contains("lost"));
|
||||
if (!p) return null;
|
||||
const a = p.getPointAtLength(0);
|
||||
const b = p.getPointAtLength(8);
|
||||
return { dy: b.y - a.y };
|
||||
});
|
||||
// The row below what shows: the curve's end turns down to the pane's foot.
|
||||
await lib.evaluate((el) => (el.scrollTop = 0));
|
||||
await still(page);
|
||||
let l = await lead();
|
||||
if (l) expect(l.dy, "turns down").toBeLessThan(0);
|
||||
// The row above what shows: it turns up.
|
||||
await lib.evaluate((el) => (el.scrollTop = el.scrollHeight));
|
||||
await still(page);
|
||||
l = await lead();
|
||||
expect(l, "a dotted curve").not.toBeNull();
|
||||
expect(l!.dy, "turns up").toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("Alt with h j k l moves between panes from a node, a selection or an article; left then right comes back; [ ] still go up and down", async ({ page }) => {
|
||||
await library(page);
|
||||
await open(page, "Library", "Infinispand");
|
||||
await open(page, "Library", "Fixed points");
|
||||
await open(page, "Fixed points", "Recursion without names");
|
||||
await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
expect(await activeTitle(page)).toBe("Recursion without names");
|
||||
await page.keyboard.press("Alt+h");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed points");
|
||||
await page.keyboard.press("Alt+l");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Recursion without names");
|
||||
await page.keyboard.press("Alt+h");
|
||||
await page.keyboard.press("Alt+k");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Infinispand");
|
||||
await page.keyboard.press("Alt+j");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed points");
|
||||
await page.keyboard.press("Alt+ArrowUp");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Infinispand");
|
||||
await keys(page, "]");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed points");
|
||||
await page.keyboard.press("Alt+h");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Library");
|
||||
await page.keyboard.press("Alt+l");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed points");
|
||||
// From a selected sentence, and from an article.
|
||||
await page.keyboard.press("Alt+l");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Recursion without names");
|
||||
await pane(page, "Recursion without names").locator(".pane-body .para").first().click({ position: { x: 40, y: 10 } });
|
||||
expect(await state(page, (s) => s.focus.grain)).toBe("sentence");
|
||||
await page.keyboard.press("Alt+h");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed points");
|
||||
await page.keyboard.press("Alt+l");
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
await pane(page, "Fixed-point combinator").locator(".wiki-head h2").dispatchEvent("click");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed-point combinator");
|
||||
await page.keyboard.press("Alt+h");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Recursion without names");
|
||||
await page.keyboard.press("Alt+l");
|
||||
await expect.poll(() => activeTitle(page)).toBe("Fixed-point combinator");
|
||||
await noFaults(page, "after moving by keys");
|
||||
});
|
||||
+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 {
|
||||
|
||||
@@ -126,6 +126,9 @@ describe("actions", () => {
|
||||
expect(labels(pane).slice(-3)).toEqual(["Pin this pane", "Close this pane", "Show as one column"]);
|
||||
expect(find(pane, "Pin this pane").checked).toBe(true);
|
||||
expect(labels(paneEntries({ article: "Octopus", pinned: false }, act)).slice(0, 2)).toEqual(["# Octopus", "Open on wikipedia.org"]);
|
||||
// Its menu goes to the panes around it, by the keys that do.
|
||||
const go = paneEntries({ article: "Octopus", pinned: false }, act).find((e) => e.t === "choices" && e.label === "Go to the pane") as Extract<Entry, { t: "choices" }>;
|
||||
expect(go.options.map((o) => `${o.label} ${o.key}`)).toEqual(["left A-h", "right A-l", "above A-k", "below A-j"]);
|
||||
});
|
||||
|
||||
it("the top menu: documents, history, undo and redo, links, the layout and settings as commands", () => {
|
||||
|
||||
Reference in new issue
Block a user