Open a note that also links as its article with the note on top
Words carrying a note and a Wikipedia link (one note with a body and a target, as the bulk linking pass made by merging links onto glosses, or a note and a link on the same words) opened only the note: a click toggled the gloss inline in both views, Enter did the same in the column, and in panes Enter opened the note's pane with the article folded to its summary. Now Enter or a click opens one page: the note's text first, then the article in full (in the column the note is hoisted and h returns to its words; in panes it is the next pane). A note's target is its own or that of a link on exactly its words. Node and web targets show their card beneath the note the same way. Browser tests cover click and keyboard in both views and the same-span case; the old test only covered the folded panes path. 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
f86a06fa06
commit
02e044af35
11 files changed
+187
-57
No files matched your search
@@ -84,7 +84,9 @@ Press `?` for every key. The short version:
|
||||
- A node can have a **target**: a Wikipedia article, another node in the library, or a web page.
|
||||
A note with a target and no text of its own is a **link**. Linked words get a thin underline and
|
||||
a mark after them, after gwern.net: **W** Wikipedia, **§** a node in this library, **↗** the web.
|
||||
A note that also links keeps its dotted underline and gets the mark.
|
||||
A note that also links keeps its dotted underline and gets the mark; `Enter` or a click on it (or on
|
||||
words that carry both a note and a link) opens one page: the note's text first, as the library's,
|
||||
then the article in full (or the node's or page's card). `h` returns to the words.
|
||||
- Hovering linked words, or landing on them with `Tab`, previews the target. `Enter` opens it: in
|
||||
panes in the next pane; in the column a preview first, then the node (Back returns) or the
|
||||
article as a page of its own. `L` opens a node's own target; a web page opens in a new tab.
|
||||
|
||||
+5
-1
@@ -2,7 +2,8 @@
|
||||
* What the browser tests share: driving the page from the keyboard, reading the store the page
|
||||
* exposes as globalThis.__ie, waiting for it to settle, and the links written into the shared
|
||||
* library over the op API, as an outside agent would (every kind of target, a note that also links,
|
||||
* a cross-document node link, two documents mentioning one article; the articles are the mock
|
||||
* a cross-document node link, two documents mentioning one article, a link and a note on the same
|
||||
* words; the articles are the mock
|
||||
* Wikipedia's fixtures in server/wikiMock.ts).
|
||||
*/
|
||||
import { writeFileSync } from "node:fs";
|
||||
@@ -85,6 +86,7 @@ export async function seedLinks(request: APIRequestContext) {
|
||||
const howY = find(s, "fixed-points", "Recursion without names", "How Y works");
|
||||
const triple = find(s, "origin-of-the-elements", "Fusion in ordinary stars", "The triple-alpha process");
|
||||
const separate = find(s, "octopus-minds", "A separate experiment");
|
||||
const ancestor = find(s, "octopus-minds", "A separate experiment", "The common ancestor");
|
||||
const programs = find(s, "what-a-proof-is", "Proof assistants", "Proofs as programs");
|
||||
const ops = [
|
||||
{ op: "create", parent: recursion, kind: "note", quote: "fixed-point combinator", ref: W("Fixed-point combinator") },
|
||||
@@ -95,6 +97,8 @@ export async function seedLinks(request: APIRequestContext) {
|
||||
{ op: "create", parent: triple, kind: "note", quote: "Fred Hoyle", ref: W("Fred Hoyle") },
|
||||
{ op: "create", parent: separate, kind: "note", quote: "octopus", ref: W("Octopus") },
|
||||
{ op: "update", id: noteOn(s, separate, "cephalopod"), ref: W("Cephalopod") },
|
||||
// A link on words that already carry a note of their own: two notes on one span.
|
||||
{ op: "create", parent: ancestor, kind: "note", quote: "The camera-like eye", ref: W("Cephalopod") },
|
||||
{ op: "create", parent: programs, kind: "note", quote: "a function turning proofs", ref: W("Lambda calculus") },
|
||||
{ op: "create", parent: programs, kind: "note", quote: "Several of the leading systems", ref: { kind: "node", id: recursion, doc: "fixed-points", path: ["Recursion without names"] } },
|
||||
];
|
||||
|
||||
+68
-9
@@ -174,7 +174,7 @@ test("panes: Tab and Enter open an article in the next pane; its sections open a
|
||||
expect(await spine.evaluate((el) => getComputedStyle(el).backgroundColor)).not.toBe(await page.locator(".pane.root .spine").evaluate((el) => getComputedStyle(el).backgroundColor));
|
||||
});
|
||||
|
||||
test("a note that also links opens as one pane: its text above, the article beneath, folded to its summary until l", async ({ page }) => {
|
||||
test("a note that also links opens as one pane: its text above, the article in full beneath", async ({ page }) => {
|
||||
await wide(page, "/doc/origin-of-the-elements");
|
||||
await inPane(page, "The triple-alpha process", "an excited state at almost exactly the energy");
|
||||
await keys(page, "Enter");
|
||||
@@ -182,22 +182,81 @@ test("a note that also links opens as one pane: its text above, the article bene
|
||||
await expect(pane).toHaveClass(/note-pane/);
|
||||
await expect(pane.locator(".body").first()).toContainText("It is called the Hoyle state");
|
||||
const block = pane.locator(".wiki.embedded");
|
||||
await expect(block).toHaveClass(/folded/);
|
||||
await expect(block.locator(".wiki-head h2")).toHaveText("Hoyle state");
|
||||
await expect(block.locator(".wattr")).toBeVisible();
|
||||
// j reaches the article under the note; l unfolds it in place; its sections are rows.
|
||||
await keys(page, "j");
|
||||
expect(await state(page, (s) => s.aux?.host?.startsWith("n"))).toBe(true);
|
||||
await keys(page, "l");
|
||||
await expect(block).not.toHaveClass(/folded/);
|
||||
await expect(block.locator(".wiki-head h2")).toHaveText("Hoyle state");
|
||||
await expect(block.locator(".wiki-text").first()).toContainText("excited, spin-0 resonant state");
|
||||
await expect(block.locator(".wattr")).toBeVisible();
|
||||
await expect(block.locator(".wrow .title")).toHaveText(["Prediction", "Structure"]);
|
||||
expect(await block.locator(".wiki-text a[data-wiki]").evaluateAll((as) => as.map((a) => a.getAttribute("data-wiki")))).toEqual(["Carbon-12", "Fred Hoyle", "Triple-alpha process"]);
|
||||
// j reaches the article under the note, then its sections; l opens one as the next pane.
|
||||
await keys(page, "j");
|
||||
expect(await state(page, (s) => s.aux?.host?.startsWith("n"))).toBe(true);
|
||||
await keys(page, "j l");
|
||||
await expect(panes(page).last().locator(".wiki-head h2")).toContainText("Prediction");
|
||||
await keys(page, "h h");
|
||||
await keys(page, "h h h");
|
||||
expect(await state(page, (s) => s.aux)).toBeNull();
|
||||
});
|
||||
|
||||
/** The page a note with a target opens as: the note's text first, as the library's, then the article. */
|
||||
async function expectCommentary(page: Page, note: string, article: string, lead: string) {
|
||||
const host = page.locator(".pane.note-pane, article:has(> header h1.note-title)").last();
|
||||
await expect(host.locator(".body").first()).toContainText(note);
|
||||
const block = host.locator(".wiki.embedded");
|
||||
await expect(block).not.toHaveClass(/folded/);
|
||||
await expect(block.locator(".wiki-head h2")).toHaveText(article);
|
||||
await expect(block.locator(".wiki-text").first()).toContainText(lead);
|
||||
// The note's text comes before the article's.
|
||||
const [n, a] = await Promise.all([host.locator(".body").first().boundingBox(), block.boundingBox()]);
|
||||
expect(n!.y).toBeLessThan(a!.y);
|
||||
}
|
||||
|
||||
test("a note that also links, clicked or entered, opens its article with the note on top, in panes and in the column", async ({ page }) => {
|
||||
const words = "an excited state at almost exactly the energy";
|
||||
const note = "It is called the Hoyle state";
|
||||
// Panes, by click.
|
||||
await wide(page, "/doc/origin-of-the-elements");
|
||||
await jump(page, "The triple-alpha process");
|
||||
await keys(page, "l");
|
||||
await panes(page).last().locator(".anchor", { hasText: words }).click();
|
||||
await expect(panes(page).last()).toHaveClass(/note-pane/);
|
||||
await expectCommentary(page, note, "Hoyle state", "excited, spin-0 resonant state");
|
||||
// The column, by keyboard: Enter on the words opens the note as a page; h returns to the words.
|
||||
await column(page, "/doc/origin-of-the-elements");
|
||||
await jump(page, "The triple-alpha process");
|
||||
await keys(page, "Enter i");
|
||||
await tabTo(page, words);
|
||||
await keys(page, "Enter");
|
||||
await expectCommentary(page, note, "Hoyle state", "excited, spin-0 resonant state");
|
||||
// Its sections open in place, as on the article page.
|
||||
for (let i = 0; i < 6 && !(await page.locator(".wrow.focused").count()); i++) await keys(page, "j");
|
||||
await keys(page, "l");
|
||||
await expect(page.locator(".wrow.open .wiki-text")).toContainText("Hoyle reasoned");
|
||||
await keys(page, "h h h");
|
||||
expect(await selected(page)).toBe(words);
|
||||
await expect(page.locator(".wiki.embedded")).toHaveCount(0);
|
||||
// The column, by click.
|
||||
await page.locator(".anchor", { hasText: words }).click();
|
||||
await expectCommentary(page, note, "Hoyle state", "excited, spin-0 resonant state");
|
||||
await page.goBack();
|
||||
await expect(page.locator(".wiki.embedded")).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a note and a link on the same words open as that one page: the note on top, the linked article beneath", async ({ page }) => {
|
||||
const words = "The camera-like eye";
|
||||
const note = "The octopus eye has a lens";
|
||||
await wide(page, "/doc/octopus-minds");
|
||||
await inPane(page, "The common ancestor", words);
|
||||
await keys(page, "Enter");
|
||||
await expectCommentary(page, note, "Cephalopod", "molluscan class Cephalopoda");
|
||||
await column(page, "/doc/octopus-minds");
|
||||
await jump(page, "The common ancestor");
|
||||
await keys(page, "l");
|
||||
await page.locator(".anchor", { hasText: words }).click();
|
||||
await expectCommentary(page, note, "Cephalopod", "molluscan class Cephalopoda");
|
||||
await keys(page, "h");
|
||||
expect(await selected(page)).toBe(words);
|
||||
});
|
||||
|
||||
test("a link to a node in another document opens it, and Back returns; in panes it opens next and h returns", async ({ page }) => {
|
||||
await column(page, "/doc/what-a-proof-is");
|
||||
await jump(page, "Proofs as programs");
|
||||
|
||||
+13
-4
@@ -9,7 +9,7 @@ import { LinkCard, LinkPicker, NodeBacklinks, NodeRelated, TargetRow } from "./L
|
||||
import { NodeBody, Outline, PendingSections, TopMatter } from "./Node";
|
||||
import { Panes } from "./Panes";
|
||||
import { PANES_MIN_WIDTH, store, type Aux } from "./store";
|
||||
import { WikiPage } from "./Wiki";
|
||||
import { WikiPage, WikiView } from "./Wiki";
|
||||
import { Usage } from "./Usage";
|
||||
|
||||
function Page() {
|
||||
@@ -21,7 +21,7 @@ function Page() {
|
||||
<TopMatter id={store.top} />
|
||||
{kids.length > 0 && <Outline ids={kids} />}
|
||||
<PendingSections id={store.top} />
|
||||
{!listing && <TargetRow id={store.top} />}
|
||||
{!listing && (store.articleUnder(store.top) ? <WikiView host={`n${store.top}`} /> : <TargetRow id={store.top} />)}
|
||||
{!listing && <NodeBacklinks id={store.top} />}
|
||||
{!listing && <NodeRelated id={store.top} />}
|
||||
</article>
|
||||
@@ -375,7 +375,9 @@ function StatusLine() {
|
||||
: selecting && store.focusedSuggestion()
|
||||
? `suggested link → ${clip(store.focusedSuggestion()!.title, 40)} · y link · n decline · Tab next · S review all`
|
||||
: selecting
|
||||
? store.noteAt(f.range)
|
||||
? store.commentaryAt(f.range)
|
||||
? `Enter opens the note with ${store.targetOf(store.commentaryAt(f.range)!)!.kind === "wiki" ? "its article" : "what it links to"} · e shows the note here · D delete note · w retarget`
|
||||
: store.noteAt(f.range)
|
||||
? store.snap.nodes[store.noteAt(f.range)!].ref
|
||||
? `Enter open the link · w retarget · D remove${store.snap.nodes[store.noteAt(f.range)!].ref!.kind === "wiki" ? " · W on Wikipedia" : ""}`
|
||||
: "Enter open/enter · e toggle · D delete note · w link it"
|
||||
@@ -535,7 +537,7 @@ export function App() {
|
||||
const targetRow = target.closest<HTMLElement>("[data-target]");
|
||||
if (targetRow) {
|
||||
store.paneAt = paneIndex;
|
||||
const r = store.snap.nodes[targetRow.dataset.target as NodeId]?.ref;
|
||||
const r = store.targetOf(targetRow.dataset.target as NodeId);
|
||||
return r && store.follow(r);
|
||||
}
|
||||
if (host && target.closest(".wiki-head")) {
|
||||
@@ -559,6 +561,13 @@ export function App() {
|
||||
const n = store.snap.nodes[id];
|
||||
const a = n.anchors[0];
|
||||
store.popup = null;
|
||||
// Words with a note and a target open as one page: the note's text, then the article.
|
||||
const both = store.commentaryAt([a.start, a.end], n.parent!);
|
||||
if (both) {
|
||||
store.paneAt = paneIndex;
|
||||
store.go(n.parent!, "word", [a.start, a.end]);
|
||||
return store.openCommentary(both);
|
||||
}
|
||||
if (n.ref && (store.panes || store.open.has(id)) && !n.body.trim()) {
|
||||
// A link: in panes it opens next to its pane; in the column, once its preview is open.
|
||||
store.paneAt = paneIndex;
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ export function LinkPreview({ id }: { id: NodeId }) {
|
||||
|
||||
/** A node's own target, as a row at the foot of its text (the column; in panes a Wikipedia target is the article itself). */
|
||||
export function TargetRow({ id }: { id: NodeId }) {
|
||||
const r = store.snap.nodes[id]?.ref;
|
||||
const r = store.targetOf(id);
|
||||
if (!r) return null;
|
||||
const focused = sameAux(store.aux, { kind: "target", of: id });
|
||||
return (
|
||||
|
||||
+6
-2
@@ -5,6 +5,7 @@ import { anchorLost, ancestors, descendants, docOf, isLibraryRoot, label, notesO
|
||||
import type { Ref } from "../core/ref";
|
||||
import { clip, overlaps, paragraphs, plain, type Form, type Range } from "../core/text";
|
||||
import { streamView } from "../core/marks";
|
||||
import { ownerSection } from "../core/links";
|
||||
import { ChoiceRows, LinkMark, LinkPreview, NodeBacklinks, NodeRelated, SuggestionCard, TargetRow, articleChoice, sectionChoice, useWikiSuggest, type Choice } from "./Links";
|
||||
import { store, type Pending } from "./store";
|
||||
|
||||
@@ -446,9 +447,12 @@ export function TopMatter({ id }: { id: NodeId }) {
|
||||
</nav>
|
||||
)}
|
||||
<header class={`top${focused ? " focused" : ""}${library ? " library" : ""}`} data-node={id}>
|
||||
<div data-row={id}>{editing ? <TitleEditor id={id} /> : <h1>{n.title || "Untitled"}</h1>}</div>
|
||||
<div data-row={id}>{editing ? <TitleEditor id={id} /> : <h1 class={n.kind === "note" ? "note-title" : undefined}>{n.title || (n.kind === "note" ? label(snap, id) : "Untitled")}</h1>}</div>
|
||||
<div class="byline">
|
||||
{library ? `${kids.length} document${kids.length === 1 ? "" : "s"}` : `${kids.length} section${kids.length === 1 ? "" : "s"}`} · {count} nodes · branch {store.repo.current}
|
||||
{n.kind === "note"
|
||||
? `a note in ${clip(label(snap, ownerSection(snap, id)), 40)}${n.by === "llm" ? ", written by the model" : ""}`
|
||||
: `${library ? `${kids.length} document${kids.length === 1 ? "" : "s"}` : `${kids.length} section${kids.length === 1 ? "" : "s"}`} · ${count} nodes`}{" "}
|
||||
· branch {store.repo.current}
|
||||
<Flags id={id} />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ class Pane extends Component<PaneProps> {
|
||||
shouldComponentUpdate(next: PaneProps) {
|
||||
if (key(next) !== key(this.props)) return true;
|
||||
if (next.p.kind === "wiki") return true;
|
||||
return store.paneDirty(next.p.id) || !!store.snap.nodes[next.p.id]?.ref || store.linkedFrom(next.p.id).length > 0;
|
||||
return store.paneDirty(next.p.id) || !!store.targetOf(next.p.id) || store.linkedFrom(next.p.id).length > 0;
|
||||
}
|
||||
render() {
|
||||
const p = this.props.p;
|
||||
@@ -85,7 +85,7 @@ function NodePane({ id, index, showing, active }: PaneProps & { id: NodeId }) {
|
||||
</ul>
|
||||
)}
|
||||
<PendingSections id={id} />
|
||||
{n.ref?.kind === "wiki" ? <WikiView host={`n${id}`} /> : <TargetRow id={id} />}
|
||||
{store.articleUnder(id) ? <WikiView host={`n${id}`} /> : <TargetRow id={id} />}
|
||||
<NodeBacklinks id={id} />
|
||||
<NodeRelated id={id} />
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ export function WikiView({ host }: { host: string }) {
|
||||
const embedded = h.embedded;
|
||||
|
||||
// Under a node, folded: its summary only, until l unfolds the article.
|
||||
if (embedded && !store.expanded.has(embedded)) {
|
||||
if (store.folded(embedded)) {
|
||||
const sum = summary(h.title, h.lang);
|
||||
return (
|
||||
<section class={`wiki embedded folded${at({ t: "head" }) ? " focused" : ""}`} data-host={host}>
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ export const HELP: [string, [string, string][]][] = [
|
||||
"Links",
|
||||
[
|
||||
["", "W marks a Wikipedia link, § another note in the library, ↗ a web page; a dotted underline is a note, both together a note that also links"],
|
||||
["Enter", "on a link: open it (panes: the next pane; column: a preview, Enter again opens it)"],
|
||||
["Enter", "on a link: open it (panes: the next pane; column: a preview, Enter again opens it). On a note that also links, or a note and a link on the same words: one page, the note's text above the article"],
|
||||
["w", "on a selection: link it (library, Wikipedia or an address); on a link: retarget it; on a node: give the node a target"],
|
||||
["L", "on a node: open its own target"],
|
||||
["W", "open the focused article on wikipedia.org, in a new tab"],
|
||||
@@ -379,7 +379,7 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
|
||||
case "Enter":
|
||||
case " ":
|
||||
if (selecting) store.enterOrExpand();
|
||||
else if (store.snap.nodes[store.focus.node]?.kind === "note" && store.snap.nodes[store.focus.node].ref) store.followOwn();
|
||||
else if (store.snap.nodes[store.focus.node]?.kind === "note" && store.targetOf(store.focus.node)) store.followOwn();
|
||||
else store.toggle();
|
||||
break;
|
||||
case "w":
|
||||
@@ -540,7 +540,7 @@ function auxKey(k: string, shift: boolean): boolean {
|
||||
// Under a node, its article opens in a pane of its own.
|
||||
const a = store.aux;
|
||||
const id = a?.kind === "wiki" && a.host.startsWith("n") ? a.host.slice(1) : a?.kind === "target" ? a.of : null;
|
||||
const r = id ? store.snap.nodes[id as keyof typeof store.snap.nodes]?.ref : undefined;
|
||||
const r = id ? store.targetOf(id as keyof typeof store.snap.nodes) : undefined;
|
||||
if (r) store.follow(r);
|
||||
return true;
|
||||
}
|
||||
|
||||
+83
-32
@@ -382,7 +382,7 @@ class Store {
|
||||
const q = this.trail[i - 1];
|
||||
if (!p || !q || p.from) return false;
|
||||
if (p.kind === "node") return q.kind === "node" && this.snap.nodes[p.id]?.parent === q.id && this.snap.nodes[p.id].kind === "section";
|
||||
return p.sec !== undefined && (q.kind === "wiki" ? q.title === p.title : this.snap.nodes[q.id]?.ref?.kind === "wiki");
|
||||
return p.sec !== undefined && (q.kind === "wiki" ? q.title === p.title : this.targetOf(q.id)?.kind === "wiki");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,14 +480,14 @@ class Store {
|
||||
const s = this.snap;
|
||||
if (!s.nodes[p.id]) return [];
|
||||
const rows: Row[] = sections(s, p.id).map((node) => ({ node }));
|
||||
return [...rows, ...this.auxRows(p.id, true)];
|
||||
return [...rows, ...this.auxRows(p.id)];
|
||||
}
|
||||
|
||||
/** Under a node: its target (in panes a Wikipedia target is the article itself, unfolded on l), then "Linked from". */
|
||||
private auxRows(id: NodeId, panes: boolean): Row[] {
|
||||
const r = this.snap.nodes[id]?.ref;
|
||||
private auxRows(id: NodeId): Row[] {
|
||||
const r = this.targetOf(id);
|
||||
const rows: Row[] = [];
|
||||
if (r?.kind === "wiki" && panes) rows.push(...this.wikiRows(`n${id}`).map((row): Row => ({ aux: { kind: "wiki", host: `n${id}`, row } })));
|
||||
if (this.articleUnder(id)) rows.push(...this.wikiRows(`n${id}`).map((row): Row => ({ aux: { kind: "wiki", host: `n${id}`, row } })));
|
||||
else if (r) rows.push({ aux: { kind: "target", of: id } });
|
||||
this.linkedFrom(id).forEach((_, index) => rows.push({ aux: { kind: "back", of: id, index } }));
|
||||
return rows;
|
||||
@@ -518,7 +518,7 @@ class Store {
|
||||
out.push({ node: id });
|
||||
if (!this.isOpen(id)) return;
|
||||
sections(s, id).forEach(visit);
|
||||
if (!(listing && id === this.top)) out.push(...this.auxRows(id, false));
|
||||
if (!(listing && id === this.top)) out.push(...this.auxRows(id));
|
||||
};
|
||||
visit(this.top);
|
||||
return out;
|
||||
@@ -556,8 +556,62 @@ class Store {
|
||||
return p?.kind === "wiki" ? { title: p.title, lang: p.lang, sec: p.sec ?? 0, mentions: p.sec === undefined } : null;
|
||||
}
|
||||
const id = host.slice(1) as NodeId;
|
||||
const r = this.snap.nodes[id]?.ref;
|
||||
return r?.kind === "wiki" ? { title: r.title, lang: r.lang, sec: 0, embedded: id } : null;
|
||||
const r = this.targetOf(id);
|
||||
// In the column its sections open in place, as on the article page.
|
||||
return r?.kind === "wiki" ? { title: r.title, lang: r.lang, sec: 0, embedded: id, nested: !this.panes } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the article under a node is folded to its summary. A section about an article opens on
|
||||
* its own text, with the article folded until l; a note's text is a commentary on the article, so
|
||||
* the article is there in full beneath it.
|
||||
*/
|
||||
folded(id: NodeId | undefined): boolean {
|
||||
return !!id && this.snap.nodes[id]?.kind === "section" && !this.expanded.has(id);
|
||||
}
|
||||
|
||||
/** Whether a node shows its Wikipedia target as the article itself: always in a pane; in the column, under a note opened as a page. */
|
||||
articleUnder(id: NodeId): boolean {
|
||||
return this.targetOf(id)?.kind === "wiki" && (this.panes || (id === this.top && this.snap.nodes[id].kind === "note"));
|
||||
}
|
||||
|
||||
/**
|
||||
* What a node is about: its own target, or, for a note with text of its own, the target of a link
|
||||
* on exactly the same words. Two notes on one span read as one: the note's text, then where the
|
||||
* link goes.
|
||||
*/
|
||||
targetOf(id: NodeId): Ref | undefined {
|
||||
const s = this.snap;
|
||||
const n = s.nodes[id];
|
||||
if (!n || n.ref || n.kind !== "note" || !n.parent || !n.body.trim() || !n.anchors[0]) return n?.ref;
|
||||
const a = n.anchors[0];
|
||||
return notesOf(s, n.parent).map((c) => s.nodes[c]).find((c) => c.ref && !c.body.trim() && c.anchors.some((b) => b.start === a.start && b.end === a.end))?.ref;
|
||||
}
|
||||
|
||||
/** On these words, the note to open as a commentary with its target: one with text and a target, its own or a link's on the same words. */
|
||||
commentaryAt(range: Range | undefined, node = this.focus.node): NodeId | undefined {
|
||||
const s = this.snap;
|
||||
if (!range || !s.nodes[node]) return;
|
||||
const texts = notesOf(s, node).filter((id) => s.nodes[id].body.trim() && s.nodes[id].anchors.some((a) => a.start === range[0] && a.end === range[1]));
|
||||
const note = texts.find((id) => s.nodes[id].ref) ?? texts[0];
|
||||
return note && this.targetOf(note) ? note : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a note that has text and a target as one page: the note's text, the library's commentary,
|
||||
* then what it is about (an article in full; a card for a node or a web page). In panes it is
|
||||
* the next pane; in the column the note is hoisted, and h at its top returns to its words.
|
||||
*/
|
||||
openCommentary(note: NodeId) {
|
||||
if (this.panes) {
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "node", id: note, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
return this.setFocus({ node: note, grain: "node" });
|
||||
}
|
||||
this.colWiki = null;
|
||||
this.colOpen.clear();
|
||||
this.setHoist(note);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,7 +623,7 @@ class Store {
|
||||
const h = this.wikiHost(host);
|
||||
if (!h) return [];
|
||||
const rows: WRow[] = [{ t: "head" }];
|
||||
if (h.embedded && !this.expanded.has(h.embedded)) return rows;
|
||||
if (this.folded(h.embedded)) return rows;
|
||||
const a = wikiArticle(h.title, h.lang);
|
||||
if (a.state === "ready") {
|
||||
if (a.value.disambiguation && h.sec === 0) {
|
||||
@@ -1051,7 +1105,10 @@ class Store {
|
||||
if (!was) return;
|
||||
const d = docOf(s, was);
|
||||
this.hoist = d && d !== was ? d : null;
|
||||
this.focus = { node: was, grain: "node" };
|
||||
// A note opened as a page steps back out to its words.
|
||||
const a = s.nodes[was].kind === "note" ? s.nodes[was].anchors[0] : undefined;
|
||||
this.focus = a ? { node: s.nodes[was].parent!, grain: "word", range: [a.start, a.end] } : { node: was, grain: "node" };
|
||||
if (a) this.reveal(this.focus.node);
|
||||
this.saveView();
|
||||
this.remember(true);
|
||||
this.emit();
|
||||
@@ -1067,7 +1124,7 @@ class Store {
|
||||
const i = Math.max(0, Math.min(units.length - 1, rangeAt(units, f.range?.[0] ?? 0) + delta));
|
||||
return this.setFocus({ ...f, range: units[i] });
|
||||
}
|
||||
if (n.kind === "note" && !this.aux && !this.paneHead(n.id)) {
|
||||
if (n.kind === "note" && !this.aux && !this.paneHead(n.id) && n.id !== this.top) {
|
||||
// Among the open notes of the same parent, in the order their anchors appear.
|
||||
const sibs = notesOf(s, n.parent!).filter((id) => this.open.has(id)).sort((a, b) => (s.nodes[a].anchors[0]?.start ?? 0) - (s.nodes[b].anchors[0]?.start ?? 0));
|
||||
const next = sibs[sibs.indexOf(n.id) + delta];
|
||||
@@ -1137,21 +1194,15 @@ class Store {
|
||||
|
||||
/** Enter on a selection: open the note anchored there, step into it if it is open, or ask for one. */
|
||||
enterOrExpand() {
|
||||
// Words with a note and a target (the note's own, or a link's on the same words) open as one
|
||||
// page: the note's text above, the article (or target) beneath.
|
||||
const both = this.commentaryAt(this.focus.range);
|
||||
if (both) return this.openCommentary(both);
|
||||
const note = this.noteAt(this.focus.range);
|
||||
if (!note) return this.expand();
|
||||
const n = this.snap.nodes[note];
|
||||
if (n.ref) {
|
||||
// A link opens its target; in panes a note that also has a target opens as a pane of its own,
|
||||
// its text above its article. In the column a link first shows a preview under its paragraph.
|
||||
if (this.panes) {
|
||||
if (!n.body.trim()) return this.follow(n.ref);
|
||||
const from = this.backHere();
|
||||
this.openPane(this.paneAt, { kind: "node", id: note, from });
|
||||
this.paneAt = this.trail.length - 1;
|
||||
return this.setFocus({ node: note, grain: "node" });
|
||||
}
|
||||
if (!n.body.trim() && this.open.has(note)) return this.follow(n.ref);
|
||||
}
|
||||
// A link opens its target: in panes at once, in the column after a preview under its paragraph.
|
||||
if (n.ref && !n.body.trim() && (this.panes || this.open.has(note))) return this.follow(n.ref);
|
||||
if (this.open.has(note)) return this.setFocus({ node: note, grain: "node" });
|
||||
this.open.add(note);
|
||||
this.saveView();
|
||||
@@ -1164,7 +1215,7 @@ class Store {
|
||||
const f = this.focus;
|
||||
const n = s.nodes[f.node];
|
||||
if (f.grain !== "node") return this.move(-1);
|
||||
if (n.kind === "note" && !this.paneHead(n.id)) {
|
||||
if (n.kind === "note" && !this.paneHead(n.id) && n.id !== this.top) {
|
||||
const a = n.anchors[0];
|
||||
return this.setFocus({ node: n.parent!, grain: a ? "word" : "node", range: a ? [a.start, a.end] : undefined });
|
||||
}
|
||||
@@ -1811,7 +1862,7 @@ class Store {
|
||||
const art = wikiArticle(h.title, h.lang);
|
||||
if (art.state !== "ready") return null;
|
||||
if (a.row.t === "head") {
|
||||
if (h.embedded && !this.expanded.has(h.embedded)) return null;
|
||||
if (this.folded(h.embedded)) return null;
|
||||
if (h.sec) return art.value.sections.find((x) => x.id === h.sec)?.html ?? null;
|
||||
return art.value.lead;
|
||||
}
|
||||
@@ -1891,7 +1942,7 @@ class Store {
|
||||
if (!a) return;
|
||||
const s = this.snap;
|
||||
if (a.kind === "target") {
|
||||
const r = s.nodes[a.of]?.ref;
|
||||
const r = this.targetOf(a.of);
|
||||
return r ? this.follow(r) : undefined;
|
||||
}
|
||||
if (a.kind === "back") return this.openLinking(this.linkedFrom(a.of)[a.index]);
|
||||
@@ -1907,8 +1958,8 @@ class Store {
|
||||
return;
|
||||
}
|
||||
if (row.t === "head") {
|
||||
if (h.embedded && !this.expanded.has(h.embedded)) {
|
||||
this.expanded.add(h.embedded);
|
||||
if (this.folded(h.embedded)) {
|
||||
this.expanded.add(h.embedded!);
|
||||
return this.emit();
|
||||
}
|
||||
return this.move(1);
|
||||
@@ -1976,7 +2027,7 @@ class Store {
|
||||
if (!target) {
|
||||
const f = this.focus;
|
||||
const note = f.grain !== "node" ? this.noteAt(f.range) : undefined;
|
||||
const r = this.snap.nodes[note ?? (a?.kind === "target" ? a.of : f.node)]?.ref;
|
||||
const r = this.targetOf(note ?? (a?.kind === "target" ? a.of : f.node));
|
||||
if (r?.kind === "wiki") target = { title: r.title, lang: r.lang };
|
||||
}
|
||||
if (!target) return this.say("No Wikipedia article here.");
|
||||
@@ -2081,9 +2132,9 @@ class Store {
|
||||
|
||||
/** L on a node: open its own target (a section about an article, a note that also links). */
|
||||
followOwn() {
|
||||
const n = this.snap.nodes[this.focus.node];
|
||||
if (!n?.ref) return this.say("This node has no target. w gives it one.");
|
||||
this.follow(n.ref);
|
||||
const r = this.targetOf(this.focus.node);
|
||||
if (!r) return this.say("This node has no target. w gives it one.");
|
||||
this.follow(r);
|
||||
}
|
||||
|
||||
setView(view: View) {
|
||||
|
||||
+2
-1
@@ -527,10 +527,11 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.wiki > .wattr { margin-top: 1.2rem; padding-top: 0.5rem; border-top: 1px solid var(--wiki-rule); }
|
||||
|
||||
/* An article under a node in its pane: clearly divided from the node's own text above it. */
|
||||
.wiki.embedded { margin: 1.6rem calc(-1 * var(--pane-pad)) 0 0; padding: 0.9rem var(--pane-pad) 0.8rem 1rem; background: var(--wiki-bg); border-top: 3px double var(--wiki-rule); }
|
||||
.wiki.embedded { margin: 1.6rem calc(-1 * var(--pane-pad, 0px)) 0 0; padding: 0.9rem var(--pane-pad, 1rem) 0.8rem 1rem; background: var(--wiki-bg); border-top: 3px double var(--wiki-rule); }
|
||||
.wiki.embedded:has(.wiki-head.focused) { box-shadow: inset 3px 0 0 var(--fg); }
|
||||
.pane-from { margin: 0 0 0.25rem; font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
|
||||
.pane.note-pane .pane-head h2 { font-style: italic; font-weight: 500; }
|
||||
.top h1.note-title { font-style: italic; font-weight: 500; }
|
||||
|
||||
/* The column's article page. */
|
||||
.wiki-page { background: var(--wiki-bg); padding: 1.2rem 1.4rem 1.4rem; border: 1px solid var(--wiki-rule); }
|
||||
|
||||
Reference in new issue
Block a user