Annotate Wikipedia articles with the same keys as nodes

An article's text is drawn from its sanitised HTML as selectable text
(articleText.ts): paragraphs, list items and quotes with their inline
elements; a formula is one unit; tables and preformatted blocks are shown
but carry no offsets. The selection ladder, Tab, Enter, e d y x c :, D and
the rest go through the same store paths as on a node; a note on article
words is a note (Enter steps into it; c, f, u, the editor and history work
on it as on any other) and shows wherever the article is opened, in the
library's own note style. Detached annotations are listed at the top of
their section with a link to the old revision. Keys that only make sense on
a node say why in the status line. Tab on a link now selects its words, so
Esc widens before h leaves, as in a node.

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:53:00 -05:00
1 parent f63fc10dc0
commit 2c1ee048a4
18 files changed
+1134 -126

No files matched your search

+21 -8
View File
@@ -1,4 +1,5 @@
/** The keymap. Modal, in the manner of vim: focus is a (node, grain) pair and most keys are one stroke. */
import { inArticles } from "../core/article";
import { store } from "./store";
export const HELP: [string, [string, string][]][] = [
@@ -10,7 +11,7 @@ export const HELP: [string, [string, string][]][] = [
["h", "close, or step out to the parent"],
["i", "narrow the grain: node → sentence → word"],
["Esc", "widen the grain; leave a note; close a panel; stop the editor while it works"],
["Tab", "jump between spans that carry a note or a link; in an article, between its links"],
["Tab", "jump between spans that carry a note or a link; in an article, between its links and the notes on it"],
["/", "jump to a section by name, in any document"],
["z", "hoist: make this node the whole page (again, or h or Esc at its top, to step out)"],
["v", "view: one column ↔ panes side by side (in panes, j k move among siblings)"],
@@ -30,6 +31,7 @@ export const HELP: [string, [string, string][]][] = [
["S", "review the suggested links of this document one by one: y link · n decline · s skip · Y link all the rest · Esc stop"],
["1–5", "the node's Related list (sections of other documents close in meaning, numbered under its text): with words selected, link them to that one; on the node, go there"],
["l h j k", "in an article: sections are rows, as in a node; l opens one, h goes back"],
["i e d y x c :", "in an article: select words of its text as in a node, and write a note on them; the note belongs to the article and shows wherever it is opened (one whose words are gone from a newer revision is listed as detached)"],
],
],
[
@@ -333,19 +335,27 @@ export function handleKey(e: KeyboardEvent, hooks: KeyHooks) {
return done();
}
if (store.panes) store.syncTrail();
// On a Wikipedia view, a target or a "Linked from" row, the keys mean what they would on rows.
if (!store.aux && ((store.panes && store.trail[store.paneAt]?.kind === "wiki") || (!store.panes && store.colWiki))) {
// On a Wikipedia view, a target or a "Linked from" row, the keys mean what they would on rows
// (unless the focus is an annotation shown in it, which is a node like any other).
const onAnnotation = !!store.snap.nodes[store.focus.node]?.wanchor || inArticles(store.snap, store.focus.node);
if (!store.aux && !onAnnotation && ((store.panes && store.trail[store.paneAt]?.kind === "wiki") || (!store.panes && store.colWiki))) {
store.aux = { kind: "wiki", host: store.panes ? `p${store.paneAt}` : "col", row: { t: "head" } };
}
if (store.aux) {
// An Enter after a Tab that is waiting for its article to arrive waits with it.
if (store.holdKey(k)) return done();
// An Enter after a Tab that is waiting for its article to arrive waits with it.
if (store.aux && store.holdKey(k)) return done();
// Words selected in an article's text take the same keys as words of a node.
if (store.aux && !store.inArticleText) {
if (auxKey(k, e.shiftKey) || commonKey(k, hooks)) return done();
const why = store.aux.kind === "wiki" ? store.articleRefuses(k, false) : null;
if (why) (store.say(why), done());
return;
}
if (commonKey(k, hooks)) return done();
const grain = store.focus.grain;
const selecting = grain !== "node";
const selecting = store.focus.grain !== "node" || store.inArticleText;
if (store.inArticleText) {
const why = store.articleRefuses(k, true);
if (why) return store.say(why), done();
}
switch (k) {
case "j":
@@ -536,6 +546,9 @@ function auxKey(k: string, shift: boolean): boolean {
case "Tab":
store.auxTab(shift ? -1 : 1);
return true;
case "i":
store.descend();
return true;
case "L": {
// Under a node, its article opens in a pane of its own.
const a = store.aux;