diff --git a/AGENTS.md b/AGENTS.md index 4c81267..c1c2b35 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,8 +24,10 @@ Keep these true: and in the code. - Opening something, a reference in place included, pushes one history entry that holds the paper's pixel, the pin, the tab and the map's camera. Following and pointing never push. -- A statement opened by a click stays until Unpin, Escape, Back or a new click. Scrolling never - lets it go. +- A statement opened by a click stays until Unpin, Escape, Back, a new click, or until the + reader scrolls on to another statement. Nobody should have to click for the Lean and the + graph to follow the reading. + graph to follow the reading. - The address names the statement carrying the highlighter, and the counter reads the same. - Failing to find a quote or a name stops the build. - `web/src/map/` is copied from lean-exposition. Keep it close to that source so fixes diff --git a/README.md b/README.md index 4637da5..e35db12 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,9 @@ the handle between the graph and the Lean to share the pane; both are remembered. Closing the proof pane lasts for that visit. As you scroll, the proof pane follows the linked passage you are reading: the Lean shows its declaration, and the graph shows that declaration with what it -uses. Choosing another card or result holds the graph there until you choose -**Follow the paper again**. Click a statement or diagram +uses, with no click needed. A statement you open by clicking it stays until you +read on to another statement. Above the Lean, the graph takes only the room its +drawing needs. Click a statement or diagram card to see its Lean code. Use **Back** to return to the diagram without losing your place, or the **Graph / Lean** toggle to choose what stays beside the paper. diff --git a/tests/journey.py b/tests/journey.py index 9122bab..5f6fca2 100644 --- a/tests/journey.py +++ b/tests/journey.py @@ -186,7 +186,7 @@ def graph_follows(page: Page, url: str, shots: Path | None) -> None: head = lambda: page.eval_on_selector_all(".nearmap__card.is-head .nearmap__title", "els => els.map(e => e.textContent)") check(page.locator(".proof__graph").bounding_box()["height"] > 150 and lean_open(page), "a fresh visit opens with the graph above the Lean") - check(page.locator(".claims--many select").count() == 1, "many results share one line with a menu") + check(page.locator(".claims--many select").count() == 0, "many results have no menu to operate") seen = set() for _ in range(8): page.mouse.move(400, 500) @@ -197,16 +197,36 @@ def graph_follows(page: Page, url: str, shots: Path | None) -> None: if "Following" in caption(page) and heads: check(any(title in caption(page) for title in heads), f"the graph shows the statement being read: {heads[0]}") check(len(seen) >= 4, f"the graph changed {len(seen)} times as the paper scrolled") - page.get_by_role("button", name="Next result").click() - page.wait_for_timeout(300) + # A statement opened by its address is held; reading on lets it go without a click. + page.goto(f"{url}#/pcp-exposition/@pcp-expository-opening", wait_until="load") + page.locator(".nearmap__card.is-head").first.wait_for() + wait_until(page, lambda: "Pinned" in caption(page), "a statement opened by its address is held open") + wait_until(page, lambda: top(page) < 1200, "the paper has arrived at that statement") + page.wait_for_timeout(600) held = head() - check(page.locator(".graph__paused").count() == 1, "choosing a result holds the graph there") - page.mouse.move(400, 500) - page.mouse.wheel(0, -4000) - page.wait_for_timeout(900) - check(head() == held, "a held graph stays put while the paper scrolls") - page.get_by_role("button", name="Follow the paper again").click() - wait_until(page, lambda: head() != held and page.locator(".graph__paused").count() == 0, "following again returns to the statement being read") + let_go = False + for _ in range(8): + page.mouse.move(400, 500) + page.mouse.wheel(0, 1100) + page.wait_for_timeout(700) + if "Following" in caption(page) and head() != held: + let_go = True + break + check(let_go, "reading on lets go of it: the Lean and the graph follow the scroll") + check(page.locator(".graph__paused").count() == 0, "and nothing asks to be clicked first") + # Whole file and back: the step's Lean is in view again. + page.locator(".proof").get_by_role("button", name="Whole file", exact=True).click() + page.wait_for_timeout(700) + page.locator(".proof").get_by_role("button", name="This step", exact=True).click() + page.wait_for_timeout(600) + check(page.evaluate("""() => { + const body = document.querySelector('.leaf__body'), line = body.querySelector('.decl .source__line'); + if (!line) return false; + const r = line.getBoundingClientRect(), b = body.getBoundingClientRect(); + return r.top >= b.top - 2 && r.bottom <= b.bottom + 2; + }"""), "back from the whole file, the step's Lean is in view") + page.goto(f"{url}#/pcp-exposition", wait_until="load") + page.locator(".papersplit").wait_for() shot(page, shots, "05-graph-follows") width = lambda: page.locator(".left").bounding_box()["width"] start = width() diff --git a/web/src/app/app.css b/web/src/app/app.css index 440d38c..a6ee096 100644 --- a/web/src/app/app.css +++ b/web/src/app/app.css @@ -467,16 +467,14 @@ a.source__ref:hover { color: var(--lit); text-decoration: underline solid; } .proof:has(.graph--near) .proof__key { display: none; } @media (prefers-reduced-motion: no-preference) { .nearmap__card, .nearmap__line { transition: opacity 120ms; } } -/* Many results: one line names the result on show, with a menu and a step either way. */ -.claims--many { flex-wrap: nowrap; align-items: center; gap: 6px; padding: 5px 12px 5px 16px; border-bottom: 1px solid var(--rule); } -.claims__pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; } +/* Many results: one quiet line says which of the paper's results is on show. */ +.claims--many { margin: 0; display: flex; flex-wrap: nowrap; align-items: baseline; gap: 10px; padding: 7px 16px 6px; border-bottom: 1px solid var(--rule); color: var(--ink); } .claims__count { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; } -.claims__pick select { flex: 1; min-width: 0; min-height: 28px; padding: 0 28px 0 8px; font: inherit; font-weight: 600; color: var(--ink); text-overflow: ellipsis; background-color: var(--sheet); border: 1px solid var(--rule-control); border-radius: var(--radius-s); cursor: pointer; } -.claims__pick select:hover { border-color: var(--ink-3); } -.claims--many .claims__step { flex: none; min-width: 28px; padding: 0; font-size: var(--fs-base); line-height: 1; color: var(--ink); border: 1px solid var(--rule-control); } -.claims--many .claims__step:hover:not(:disabled) { border-color: var(--ink-3); } -.claims--many .claims__step:disabled { color: var(--ink-3); opacity: 0.5; cursor: default; } -.claims__pick select:focus-visible, .claims__step:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; } +.claims--many b { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.graph__usedby .graph__more { color: var(--ink-2); } +/* Above the Lean, the graph is as tall as its drawing needs, never more than its share. */ +.proof:not([data-side]) .proof__panes.is-both > .proof__graph { flex: 0 0 auto; height: min(calc(var(--share) * 100%), var(--graph-want, 100%)); } +.proof:not([data-side]) .proof__panes.is-both > .proof__lean { flex: 1 1 0; } /* The drawing changes with the statement being read: a short dissolve says it is a new drawing. */ @media (prefers-reduced-motion: no-preference) { .nearmap__world { animation: nearmap-arrive 180ms cubic-bezier(0.16, 1, 0.3, 1) backwards; } diff --git a/web/src/paper/PaperPage.tsx b/web/src/paper/PaperPage.tsx index 959aaa2..b2c8955 100644 --- a/web/src/paper/PaperPage.tsx +++ b/web/src/paper/PaperPage.tsx @@ -452,7 +452,18 @@ export function PaperPage({ edition }: { edition: Edition }) { else letGo(layoutRef.current.lean); }, [closeSheet, letGo, setMode, wide]); - const onFollow = useCallback((id, zone, above) => { + const lineId = useRef(null); + const onFollow = useCallback((id, zone, above, byReader) => { + // Reading on lets go of a statement held open: once the reader has scrolled to another + // statement, the Lean and the graph follow the reading line again. + const cur = entryRef.current; + if (byReader && cur.pin && cur.tab === "step" && id && id !== lineId.current && id !== cur.pin.passage) { + const unpinned = { ...cur, pin: null, lean: layoutRef.current.lean, opened: null }; + entryRef.current = unpinned; + setEntry(unpinned); + setMapStays(false); + } + lineId.current = id; setLine({ id, zone, above }); if (above) lastPassage.current = above; const at = id ?? above; diff --git a/web/src/paper/ReadingPane.tsx b/web/src/paper/ReadingPane.tsx index efae5fb..0a609e8 100644 --- a/web/src/paper/ReadingPane.tsx +++ b/web/src/paper/ReadingPane.tsx @@ -184,7 +184,7 @@ export const ReadingPane = forwardRef(function ReadingPane(p const followSoon = useCallback((id: string | null, kind: Zone, above: string | null) => { window.clearTimeout(followTimer.current); - followTimer.current = window.setTimeout(() => latest.current.onFollow(id, kind, above), FOLLOW_MS); + followTimer.current = window.setTimeout(() => latest.current.onFollow(id, kind, above, userMoved.current), FOLLOW_MS); }, []); /** What the reading line shows now. */ diff --git a/web/src/paper/reading-line.ts b/web/src/paper/reading-line.ts index 1392f3a..9fae5cd 100644 --- a/web/src/paper/reading-line.ts +++ b/web/src/paper/reading-line.ts @@ -8,7 +8,8 @@ export const READING_LINE = 0.34; export const FOLLOW_MS = 200; /** What the left page is called on when a statement settles. */ -export type Follow = (id: string | null, zone: Zone, above: string | null) => void; +/** `byReader`: the reader scrolled here; a jump the page made itself does not count. */ +export type Follow = (id: string | null, zone: Zone, above: string | null, byReader?: boolean) => void; /** How long a pointer rests before the right page previews. */ export const DWELL_MS = 150; diff --git a/web/src/paper/reading.css b/web/src/paper/reading.css index 7a4d5f6..b7ea840 100644 --- a/web/src/paper/reading.css +++ b/web/src/paper/reading.css @@ -225,6 +225,8 @@ dialog.plot p { margin: 8px 0 0; font-family: var(--font-sans); font-size: var(- /* Author Markdown tables: the original cells remain one semantic table. */ .sheet__text table { display: block; + /* As wide as its cells, centred on the text column; a table wider than the page scrolls. */ + width: fit-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; diff --git a/web/src/proof/LeanPage.tsx b/web/src/proof/LeanPage.tsx index 9fa2283..31a35dd 100644 --- a/web/src/proof/LeanPage.tsx +++ b/web/src/proof/LeanPage.tsx @@ -85,14 +85,20 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start // pane; a step come back to keeps its place. const shownOpen = useRef(false); const arriving = useRef(true); + const tabWas = useRef(tab); useLayoutEffect(() => { const el = body.current; if (!el || !open) { shownOpen.current = false; return; } + // The whole file and the index scroll this same page. Coming back to the step, place + // it afresh: their scroll position means nothing here. + const back = tab === "step" && tabWas.current !== "step"; + tabWas.current = tab; + if (tab !== "step") return; const was = shownKey.current; - if (was === step.key && shownOpen.current) return; + if (was === step.key && shownOpen.current && !back) return; if (was !== step.key && shownOpen.current) tops.current.set(was, el.scrollTop); shownKey.current = step.key; shownOpen.current = true; @@ -103,7 +109,7 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start return; } } - const kept = tops.current.get(step.key); + const kept = back ? undefined : tops.current.get(step.key); if (kept !== undefined) { el.scrollTop = kept; return; @@ -129,7 +135,7 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start if (target > 0 && target < top) target = fits(0) ? 0 : top; el.scrollTop = Math.max(0, target); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [open, step]); + }, [open, step, tab]); return (
diff --git a/web/src/proof/MapPane.tsx b/web/src/proof/MapPane.tsx index f2fda54..1839d57 100644 --- a/web/src/proof/MapPane.tsx +++ b/web/src/proof/MapPane.tsx @@ -27,6 +27,8 @@ const BAND = 340; const MAP_LIMIT = 16; /** More results than this, and the switch between them is one line with a menu. */ const MANY_CLAIMS = 4; +/** How many users of a card are named before "and N more". */ +const USERS_SHOWN = 3; const LIST_BELOW = 440; /** Neighbourhood tiles are wider, and each is as tall as its title needs, up to four lines. */ const NEAR_W = 140; @@ -179,6 +181,9 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l }; }, [big, edition.slug]); const graph = useMemo(() => (near ? neighbourhood(edition, fullGraph, centre, goal, files) : fullGraph), [near, edition, fullGraph, centre, goal, files]); + // A much-used definition has dozens of users: name a few, with the rest one press away. + const [allUsers, setAllUsers] = useState(false); + useEffect(() => setAllUsers(false), [centre]); const usedBy = useMemo(() => (near && centre !== goal ? (edition.declarations.find((d) => d.id === centre)?.used_by ?? []) : []), [near, centre, goal, edition]); // What the pointer or focus is on, for the "via" line under the controls. const [hovered, setHovered] = useState(null); @@ -217,9 +222,14 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l useEffect(() => { if (selected) show(selected); }, [selected, show]); + // A card the reader chose in the graph stays in view only until they read on: the next + // statement to reach the reading line takes the graph back. No button is needed. + const [held, setHeld] = useState(null); useEffect(() => { - if (!selected && followed && !paused) show(followed); - }, [selected, followed, paused, show]); + if (selected || !followed || followed === held) return; + setHeld(null); + show(followed); + }, [selected, followed, held, show]); const litIds = useMemo(() => (lit.length ? new Set(lit) : null), [lit]); const litKey = lit.join("|"); const litRef = useRef(lit); @@ -286,8 +296,8 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l const browse = useCallback((id: string) => { if (claims.some((c) => c.id === id)) setGoal(id); setCentre(id); - if (litRef.current.length) setPause(true); - }, [claims, setPause]); + setHeld(litRef.current.find((x) => edition.declarations.some((d) => d.id === x)) ?? ""); + }, [claims, edition]); const restoring = useRef(false); useImperativeHandle(ref, (): MapPaneHandle => ({ @@ -439,7 +449,7 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
{paused && (

- The graph stays where you put it. + Paused while you move the graph.

)} @@ -450,17 +460,11 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l ))} )} - {claims.length > MANY_CLAIMS && ( -
- - - -
+ {claims.length > MANY_CLAIMS && (!near || centre === goal) && ( +

+ Result {claimAt + 1} of {claims.length} + {claim?.title} +

)} {types.length > 0 && (
@@ -482,11 +486,16 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l {whole ? "Show one card and what it uses" : "Whole map"} )} - {near && !narrow && centre !== goal && } + {near && !narrow && centre !== goal && claims.length <= MANY_CLAIMS && } {near && !narrow && centre !== goal && } {near && !narrow && usedBy.length > 0 && ( Used by{" "} - {usedBy.map((id) => )} + {(allUsers ? usedBy : usedBy.slice(0, USERS_SHOWN)).map((id) => )} + {usedBy.length > USERS_SHOWN && ( + + )} )} {whole && big && !narrow && Point at a card to see its lines.} diff --git a/web/src/proof/NearMap.tsx b/web/src/proof/NearMap.tsx index 2ea560c..e3e8e8f 100644 --- a/web/src/proof/NearMap.tsx +++ b/web/src/proof/NearMap.tsx @@ -313,6 +313,23 @@ export function NearMap({ graph, heads, plate, kicker = "Main result", alone, li return { placed, lines, height: y + 12, crossings, behind, kinds, edges, bands }; }, [graph, heads, plate, width]); + // Above the Lean, the graph takes only the room its drawing needs, up to the share the + // reader has given it: a card with two uses leaves the rest of the page to its Lean. + const tail = useRef(null); + useLayoutEffect(() => { + const el = frame.current; + const pane = el?.closest(".proof__graph"); + const panes = el?.closest(".proof__panes"); + if (!el || !pane || !panes || !drawing) return; + const above = el.getBoundingClientRect().top - pane.getBoundingClientRect().top; + panes.style.setProperty("--graph-want", `${Math.ceil(above + drawing.height + (tail.current?.offsetHeight ?? 0) + 14)}px`); + }, [drawing, alone]); + useEffect(() => { + const panes = frame.current?.closest(".proof__panes"); + return () => { + panes?.style.removeProperty("--graph-want"); + }; + }, []); // Shrink to fit the pane with the one-line key under the drawing; past MIN_SCALE it scrolls. const KEY_H = 34; const fit = drawing && paneH ? Math.max(MIN_SCALE, Math.min(1, (paneH - KEY_H) / drawing.height)) : 1; @@ -370,9 +387,9 @@ export function NearMap({ graph, heads, plate, kicker = "Main result", alone, li
)} - {drawing && drawing.edges.length === 0 && alone &&

{alone}

} + {drawing && drawing.edges.length === 0 && alone &&

{alone}

} {drawing && drawing.edges.length > 0 && ( -

+

{drawing.kinds.size > 1 ? "Lines run down to what a card uses; dashed: its statement only." diff --git a/web/src/proof/ProofPage.tsx b/web/src/proof/ProofPage.tsx index d991e59..7e0e5e8 100644 --- a/web/src/proof/ProofPage.tsx +++ b/web/src/proof/ProofPage.tsx @@ -11,7 +11,7 @@ const KEY = "proof-reader-pane-3"; /** Narrower than this, the graph sits above the Lean; from here they stand side by side. */ const SIDE_BY_SIDE = 1040; /** What the graph has before the reader pulls the handle: the statement's place in the proof, above or beside its Lean. */ -const OPENING = { share: 0.4, sideShare: 0.46 }; +const OPENING = { share: 0.6, sideShare: 0.46 }; const MAX = 0.78; /** A pull shorter than this leaves the Lean the whole page. */ const SHUT = 0.08;