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:
thalladaandClaude Opus 5.5 committed 2026-11-15 21:10:19 -05:00
1 parent f86a06fa06
commit 02e044af35
11 files changed
+187 -57

No files matched your search

+13 -4
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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); }