Mouse layer: one helper per repeated pointer lookup, dead hooks and options out

- A click (App) and a right-click or ⋯ (Mouse focusAt) each worked out
  the pane under the pointer, its article host and the words dragged
  over; they share pointedPane, dragged and wtextRow now.
- The page's Act lives with the menus that use it (Mouse.tsx), so
  actions.ts is the pure builders its header says it is.
- App's key handler: one openCommand for the prompt hook and the key
  handler, dropPopup instead of a copy of it, closeMenu without the
  menuShown check it makes itself.
- Gone: the "page" menu place (it took the same branches as "auto"),
  Key's shift prop and the arrow keys' text (never passed), isFirstRun,
  HistoryPanel's lastType (implied by the set of heads), and DOM
  attributes nothing reads (data-libs-trigger, data-conflict,
  data-popup, data-source, lib-new). Exports used only in their file
  are not exported.

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-17 16:25:27 -05:00
1 parent fbd2a0852a
commit 2e3ffbb7cd
6 files changed
+99 -110

No files matched your search

+22 -38
View File
@@ -10,10 +10,10 @@ import { LinkCard, LinkPicker, LinksPanel, NodeBacklinks, NodeRelated, TargetRow
import { NodeBody, Outline, PendingSections, TopMatter } from "./Node";
import { Panes } from "./Panes";
import { PaneMap, Trail } from "./Pages";
import { PANES_MIN_WIDTH, store, type Aux, type WRow } from "./store";
import { PANES_MIN_WIDTH, store, type Aux } from "./store";
import { WikiPage, WikiView } from "./Wiki";
import { Usage } from "./Usage";
import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, hideBar, locate, locateIn, menuAt, menuShown, setCard, setPrompt, showBar, touch, type Hint } from "./Mouse";
import { FirstRun, Hints, Key, MenuHost, SelBar, closeMenu, dragged, hideBar, locate, locateIn, menuAt, pointedPane, setCard, setPrompt, showBar, touch, wtextRow, type Hint } from "./Mouse";
import { press } from "./press";
function Page() {
@@ -45,7 +45,7 @@ function ConflictCard({ c, selected }: { c: Conflict; selected: boolean }) {
const kind = { "edit-edit": "both sides rewrote this", "edit-delete": "edited on one side, deleted on the other", contradiction: "contradicts another node" }[c.type];
const other = c.other && store.snap.nodes[c.other] ? label(store.snap, c.other) : null;
return (
<div class={`item conflict ${c.status}${selected ? " selected" : ""}`} data-conflict={c.id}>
<div class={`item conflict ${c.status}${selected ? " selected" : ""}`}>
<div class="line">
<b>{c.title || "(untitled)"}</b>
<span class="chip">{c.status}</span>
@@ -95,14 +95,13 @@ function HistoryPanel({ verdict }: { verdict: string }) {
ref.current?.querySelector(".selected")?.scrollIntoView({ block: "nearest" });
});
const heads = new Set<string>();
let lastType = "";
const live = store.doc.snap();
const filter = store.historyFilter && live.nodes[store.historyFilter] ? store.historyFilter : null;
const onRoot = isLibraryRoot(live, store.activeNode);
return (
<aside class="panel" ref={ref}>
<div class="panel-head">
<span>History{filter ? ` · ${clip(label(store.doc.snap(), filter), 30)}` : " · the library"}</span>
<span>History{filter ? ` · ${clip(label(live, filter), 30)}` : " · the library"}</span>
<span class="keys">
<Hints hint={["j k", ["Enter", "view"], ["r", `revert ${onRoot ? "the library" : "this node"}`], ["n", "branch"], ["m", "merge"], ["f", filter ? "everything" : "this node"], ["v", "verify"], ["Escape", "close"]]} />
</span>
@@ -110,8 +109,7 @@ function HistoryPanel({ verdict }: { verdict: string }) {
{verdict && <div class="verdict">{verdict}</div>}
{items.map((it, i) => {
const selected = i === store.historyIndex;
const head = it.type !== lastType && !heads.has(it.type) ? ({ conflict: "Conflicts", branch: "Branches", commit: "Commits" } as const)[it.type] : null;
lastType = it.type;
const head = !heads.has(it.type) ? ({ conflict: "Conflicts", branch: "Branches", commit: "Commits" } as const)[it.type] : null;
heads.add(it.type);
const pick = () => {
store.historyIndex = i;
@@ -258,7 +256,6 @@ function Jump({ move }: { move?: boolean }) {
function CommandBar({ prefill }: { prefill: string }) {
const f = store.focus;
const snap = store.snap;
const n = snap.nodes[f.node];
const words = store.selectedText();
const about = words !== null ? `ask about “${clip(plain(words), 48)}”` : `tell the editor · ${clip(label(snap, f.node), 40)}`;
return (
@@ -311,7 +308,7 @@ function Popup() {
const snap = store.snap;
if (!p || !snap.nodes[p.note] || store.open.has(p.note)) return null;
return (
<div class="popup" style={place(p.x, p.top, p.bottom)} data-popup={p.note}>
<div class="popup" style={place(p.x, p.top, p.bottom)}>
<PopupBody note={p.note} />
</div>
);
@@ -338,7 +335,7 @@ function FocusPopup() {
});
if (!note || !n?.ref || store.open.has(note)) return null;
return (
<div class="popup focus-popup" ref={ref} data-popup={note} style={{ visibility: "hidden" }}>
<div class="popup focus-popup" ref={ref} style={{ visibility: "hidden" }}>
<PopupBody note={note} />
</div>
);
@@ -373,7 +370,7 @@ function AgentPanel() {
{run.sources.map((s, i) => (
<span key={s.url}>
{i ? " · " : ""}
<a href={s.url} target="_blank" rel="noopener noreferrer" data-source={s.url}>
<a href={s.url} target="_blank" rel="noopener noreferrer">
{s.title || hostOf(s.url)}
</a>{" "}
<span class="agent-host">{hostOf(s.url)}</span>
@@ -442,7 +439,7 @@ function StatusLine() {
: [];
return (
<footer class="status">
<span class={`grain ${lp ? "aux" : store.aux ? "aux" : f.grain}`}>{lp ? "libraries" : store.preview ? "history" : store.mode === "review" ? "review" : store.aux ? (store.aux.kind === "wiki" ? "article" : store.aux.kind === "back" ? "linked" : "target") : f.grain}</span>
<span class={`grain ${lp || store.aux ? "aux" : f.grain}`}>{lp ? "libraries" : store.preview ? "history" : store.mode === "review" ? "review" : store.aux ? (store.aux.kind === "wiki" ? "article" : store.aux.kind === "back" ? "linked" : "target") : f.grain}</span>
<span class="path">{path}</span>
<span class="message">{libsHint ? <Hints hint={libsHint} /> : reviewing ? <Hints hint={reviewing} /> : store.status || (hint.length ? <Hints hint={hint} /> : <FirstRun />)}</span>
<span class="right">
@@ -486,10 +483,11 @@ export function App() {
useEffect(() => store.subscribe(() => tick(0)), []);
useEffect(() => {
setPrompt((text) => {
const openCommand = (text = "") => {
setPrefill(text);
store.setMode("command");
});
};
setPrompt(openCommand);
// A long press on a link (touch) shows what it opens above its menu.
setCard((note) => <PopupBody note={note} />);
const onKey = (e: KeyboardEvent) => {
@@ -502,17 +500,11 @@ export function App() {
// The keys take over from the pointer: its bar and menu go (not for a modifier, or the copy key).
if (!e.ctrlKey && !e.metaKey && !e.altKey && !["Shift", "Control", "Alt", "Meta"].includes(e.key)) {
hideBar();
if (menuShown()) closeMenu(false);
}
if (store.popup) {
store.popup = null;
store.emit(store.top);
closeMenu(false);
}
dropPopup();
handleKey(e, {
openCommand(text = "") {
setPrefill(text);
store.setMode("command");
},
openCommand,
verify() {
const t = performance.now();
const v = verifyHistory(store.doc);
@@ -619,18 +611,13 @@ export function App() {
// A pane's × and pin act on that pane, wherever the focus is.
const ctl = target.closest<HTMLElement>("[data-close], [data-pin]");
if (ctl) return ctl.dataset.close ? store.closePane(Number(ctl.dataset.close)) : store.togglePanePin(Number(ctl.dataset.pin));
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
const { paneEl, paneIndex, tid, host } = pointedPane(target);
// A pane in another fork: that fork becomes the focused branch first, then the click does what it would there.
const tid = paneEl ? Number(paneEl.dataset.tid) : undefined;
if (tid !== undefined && store.branchNodes[paneIndex]?.id !== tid) store.enterFork(tid);
// A covered pane's spine brings that pane back by focusing it.
const spine = target.closest<HTMLElement>("[data-spine]");
if (spine) return store.land(Number(spine.dataset.spine));
// Article text: a link to another article opens it next; a link out leaves in a new tab (the HTML says so); nothing else navigates.
const named = target.closest<HTMLElement>("[data-host]")?.dataset.host;
// An article pane off the branch is named by its place in the tree; on the branch, by its column.
const host = named?.startsWith("f") ? `p${paneIndex}` : named;
const a = target.closest<HTMLAnchorElement>("a");
if (a && host) {
if (a.dataset.wiki) {
@@ -677,7 +664,7 @@ export function App() {
const wtext = target.closest<HTMLElement>("[data-wtext]");
if (host && wtext && !target.closest("[data-node]")) {
store.paneAt = paneIndex;
const row = (wtext.dataset.wtext === "head" ? { t: "head" } : { t: "sec", id: Number(wtext.dataset.wtext) }) as WRow;
const row = wtextRow(wtext);
const at = (n: Node | null, o: number) => (n && wtext.contains(n) ? locateIn(n, o) : null);
const a = selection && !selection.isCollapsed ? at(selection.anchorNode, selection.anchorOffset) : null;
const b = selection && !selection.isCollapsed ? at(selection.focusNode, selection.focusOffset) : null;
@@ -693,14 +680,11 @@ export function App() {
return;
}
// A drag selection inside one body becomes the focus range.
if (selection && !selection.isCollapsed && !store.replacing) {
const a = locate(selection.anchorNode, selection.anchorOffset);
const b = locate(selection.focusNode, selection.focusOffset);
if (a && b && a.id === b.id && a.at !== b.at) {
store.go(a.id, "word", [Math.min(a.at, b.at), Math.max(a.at, b.at)]);
selection.removeAllRanges();
return showBar();
}
const d = store.replacing ? null : dragged(selection);
if (d) {
store.go(d.id, "word", d.range);
selection!.removeAllRanges();
return showBar();
}
const anchor = target.closest<HTMLElement>("[data-note]");
if (anchor?.dataset.note) {
+3 -6
View File
@@ -5,7 +5,7 @@
import { useLayoutEffect, useRef } from "preact/hooks";
import { libraryEntries, topEntries } from "./actions";
import { nodeCount } from "./libraries";
import { Hints, Key, act, showMenu, type Hint } from "./Mouse";
import { Hints, Key, act, showMenu } from "./Mouse";
import { press } from "./press";
import { store } from "./store";
@@ -21,7 +21,6 @@ const SAVE_TITLE = {
deleted: "The server no longer has this library: it was deleted, and its files moved aside. Open another from the libraries (m).",
};
export function DocBar() {
const state = store.saveState();
const snap = store.snap;
@@ -30,7 +29,6 @@ export function DocBar() {
<button
type="button"
class="tool lib-name"
data-libs-trigger
aria-haspopup="dialog"
aria-expanded={store.libs ? "true" : "false"}
title="The libraries: open, make, rename or delete one (m)"
@@ -126,13 +124,12 @@ export function LibrariesPanel() {
if (!l) return;
showMenu(libraryEntries({ title: l.title, current: id === store.library && !store.gone, last: only }, act), at);
};
const head: Hint = [["n", "new"], ["Escape", "close"]];
return (
<aside class="panel left libraries" ref={ref} data-libraries data-loading={p.loading ? "1" : undefined} aria-label="Libraries">
<div class="panel-head">
<span>Libraries{p.loading ? " …" : ""}</span>
<span class="keys">
<Hints hint={head} />
<Hints hint={[["n", "new"], ["Escape", "close"]]} />
</span>
</div>
{store.gone && <div class="verdict lib-gone">This library was deleted on the server, and its files moved aside; what was edited here since is not saved. Open another:</div>}
@@ -189,7 +186,7 @@ export function LibrariesPanel() {
})}
{!rows.length && <p class="lempty">{p.loading ? "Asking the server…" : "No other library."}</p>}
{p.edit?.kind === "new" ? (
<div class="item lib-row lib-new selected">
<div class="item lib-row selected">
<div class="line">
<span class="lib-mark">+</span>
<NameBox initial="" />
+69 -33
View File
@@ -12,7 +12,7 @@ import { createPortal } from "preact/compat";
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import { isLibraryRoot, label, staleness, topOf, type NodeId } from "../core/model";
import { plain } from "../core/text";
import { articleRowEntries, barItems, nodeEntries, pageAct, paneEntries, selectionEntries, topEntries, type Entry, type Item, type NodeCtx, type SelCtx } from "./actions";
import { articleRowEntries, barItems, nodeEntries, paneEntries, selectionEntries, type Act, type Entry, type Item, type NodeCtx, type SelCtx } from "./actions";
import { press } from "./press";
import { store, type WRow } from "./store";
@@ -34,6 +34,29 @@ export function locate(node: Node | null, offset: number): { id: NodeId; at: num
return { id: body.dataset.body as NodeId, at: Number(piece.dataset.o) + (node instanceof Text ? offset : 0) };
}
/** Words dragged over inside one body, as its node and the range. */
export function dragged(sel: Selection | null): { id: NodeId; range: [number, number] } | null {
if (!sel || sel.isCollapsed) return null;
const a = locate(sel.anchorNode, sel.anchorOffset);
const b = locate(sel.focusNode, sel.focusOffset);
return a && b && a.id === b.id && a.at !== b.at ? { id: a.id, range: [Math.min(a.at, b.at), Math.max(a.at, b.at)] } : null;
}
/**
* The pane a pointer is in (else the active one), and the article host it is in: an article pane
* off the branch is named by its place in the tree; on the branch, by its column.
*/
export function pointedPane(target: HTMLElement) {
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
const tid = paneEl ? Number(paneEl.dataset.tid) : undefined;
const named = target.closest<HTMLElement>("[data-host]")?.dataset.host;
return { paneEl, paneIndex, tid, host: named?.startsWith("f") ? `p${paneIndex}` : named };
}
/** The row of an article's text an element is in: its head or a section. */
export const wtextRow = (wtext: HTMLElement) => (wtext.dataset.wtext === "head" ? { t: "head" } : { t: "sec", id: Number(wtext.dataset.wtext) }) as WRow;
/** The text position under a point. */
function caretAt(x: number, y: number): { node: Node; offset: number } | null {
const d = document as Document & { caretPositionFromPoint?(x: number, y: number): { offsetNode: Node; offset: number } | null; caretRangeFromPoint?(x: number, y: number): Range | null };
@@ -56,7 +79,30 @@ export const setPrompt = (fn: (prefill: string) => void) => (promptHook = fn);
let cardHook: (note: NodeId) => ComponentChildren = () => null;
/** What a link's card is drawn with, above a menu on touch (App.tsx: the hover preview's body). */
export const setCard = (fn: (note: NodeId) => ComponentChildren) => (cardHook = fn);
export const act = pageAct({ command: (t) => store.command(t), prompt: (p) => promptHook(p) });
/** The page's own `Act`: keys through the key handler, commands through the command bar's handler. */
export const act: Act = {
press,
command: (t) => store.command(t),
prompt: (p) => promptHook(p),
copy(text) {
if (navigator.clipboard) navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
else fallbackCopy(text);
},
};
function fallbackCopy(text: string) {
const t = document.createElement("textarea");
t.value = text;
t.style.position = "fixed";
t.style.opacity = "0";
document.body.appendChild(t);
t.select();
try {
document.execCommand("copy");
} finally {
t.remove();
}
}
// ---- what is focused, for the menus ----
@@ -99,11 +145,11 @@ function selCtx(): SelCtx {
};
}
/** Which menu a place asks for: what is focused there, or the pane it is in, or the page's head. */
export type Where = "auto" | "pane" | "page";
/** Which menu a place asks for: what is focused there, or the pane it is in. */
type Where = "auto" | "pane";
/** The menu for what is focused now. */
export function menuHere(where: Where): Entry[] {
function menuHere(where: Where): Entry[] {
if (store.mode !== "normal") return [];
if (store.selectedText() !== null) return selectionEntries(selCtx(), act);
const a = store.aux;
@@ -128,38 +174,31 @@ export function menuHere(where: Where): Entry[] {
* sentence), a row, a note's box, a pane's head or the pane, an article's row or text. Returns
* which menu to show, or null where the browser's own menu belongs.
*/
export function focusAt(target: HTMLElement, x: number, y: number): Where | null {
function focusAt(target: HTMLElement, x: number, y: number): Where | null {
if (store.mode !== "normal") return null;
const more = !!target.closest("[data-more]");
const paneEl = target.closest<HTMLElement>("[data-pane-index]");
const paneIndex = paneEl ? Number(paneEl.dataset.paneIndex) : store.paneAt;
const tid = paneEl ? Number(paneEl.dataset.tid) : undefined;
const { paneEl, paneIndex, tid, host } = pointedPane(target);
const intoPane = () => {
if (!paneEl) return;
if (tid !== undefined && store.branchNodes[paneIndex]?.id !== tid) store.enterFork(tid);
store.paneAt = paneIndex;
};
const named = target.closest<HTMLElement>("[data-host]")?.dataset.host;
const host = named?.startsWith("f") ? `p${paneIndex}` : named;
if (!more) {
// In the selection: keep it.
if (target.closest(".sel") && store.selectedText() !== null) return "auto";
// Words dragged over, not yet taken (a long press on a touch screen selects a word this way).
const sel = window.getSelection();
if (sel && !sel.isCollapsed) {
const a = locate(sel.anchorNode, sel.anchorOffset);
const b = locate(sel.focusNode, sel.focusOffset);
if (a && b && a.id === b.id && a.at !== b.at) {
intoPane();
store.go(a.id, "word", [Math.min(a.at, b.at), Math.max(a.at, b.at)]);
sel.removeAllRanges();
return "auto";
}
const d = dragged(sel);
if (d) {
intoPane();
store.go(d.id, "word", d.range);
sel!.removeAllRanges();
return "auto";
}
// An article's text: the sentence there.
const wtext = target.closest<HTMLElement>("[data-wtext]");
if (host && wtext && !target.closest("[data-node]")) {
const row = (wtext.dataset.wtext === "head" ? { t: "head" } : { t: "sec", id: Number(wtext.dataset.wtext) }) as WRow;
const row = wtextRow(wtext);
const at = caretAt(x, y);
const o = at && wtext.contains(at.node) ? locateIn(at.node, at.offset) : null;
if (o === null) return null;
@@ -197,7 +236,7 @@ export function focusAt(target: HTMLElement, x: number, y: number): Where | null
if (row) {
intoPane();
store.go(row.dataset.row as NodeId);
return row.closest(".top") ? (paneEl ? "pane" : "page") : "auto";
return row.closest(".top") && paneEl ? "pane" : "auto";
}
if (host && target.closest(".wiki-head")) {
intoPane();
@@ -208,7 +247,7 @@ export function focusAt(target: HTMLElement, x: number, y: number): Where | null
if (node?.dataset.node && store.snap.nodes[node.dataset.node as NodeId]) {
intoPane();
store.go(node.dataset.node as NodeId);
return node.matches(".pane-head") || (paneEl && node.matches(".top")) ? "pane" : node.matches(".top") ? "page" : "auto";
return node.matches(".pane-head") || (paneEl && node.matches(".top")) ? "pane" : "auto";
}
if (paneEl && (more || target.closest(".pane-scroll, .pane-ctl"))) {
intoPane();
@@ -269,18 +308,17 @@ export function closeMenu(refocus = true) {
else if (document.activeElement?.closest(".menu")) (document.activeElement as HTMLElement).blur();
}
export const menuShown = () => !!shown;
const KEY_TEXT: Record<string, string> = { Enter: "⏎", Escape: "Esc", ArrowUp: "↑", ArrowDown: "↓" };
const KEY_TEXT: Record<string, string> = { Enter: "⏎", Escape: "Esc" };
/** How a key is written beside what it does. */
export const keyText = (k: string) => KEY_TEXT[k] ?? (k.startsWith("A-") ? `Alt+${k.slice(2)}` : k);
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
* hangs from; on touch, a sheet from the foot of the screen. ↑ ↓ (and Home End) move, Enter runs,
* Esc closes and puts the focus back where it was; a press outside closes it too.
*/
export function Menu({ entries, at, sheet, card, onClose }: { entries: Entry[]; at: Shown["at"]; sheet: boolean; card?: NodeId; onClose: (refocus: boolean) => void }) {
function Menu({ entries, at, sheet, card, onClose }: { entries: Entry[]; at: Shown["at"]; sheet: boolean; card?: NodeId; onClose: (refocus: boolean) => void }) {
const ref = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
const el = ref.current!;
@@ -328,8 +366,7 @@ export function Menu({ entries, at, sheet, card, onClose }: { entries: Entry[];
const all = cells();
const i = all.indexOf(document.activeElement as HTMLElement);
const go = (j: number) => (e.preventDefault(), all[(j + all.length) % all.length]?.focus());
if (e.key === "Escape") return e.preventDefault(), onClose(true);
if (e.key === "Tab") return e.preventDefault(), onClose(true);
if (e.key === "Escape" || e.key === "Tab") return e.preventDefault(), onClose(true);
if (e.key === "ArrowDown" || (e.key === "ArrowRight" && i >= 0 && all[i].closest(".choices"))) return go(i + 1);
if (e.key === "ArrowUp" || (e.key === "ArrowLeft" && i >= 0 && all[i].closest(".choices"))) return go(i < 0 ? -1 : i - 1);
if (e.key === "Home") return go(0);
@@ -547,13 +584,13 @@ export function SelBar() {
export type Hint = (string | [key: string, what: string])[];
/** A key hint that is a button: a click does what the key does. */
export function Key({ k, what, shift }: { k: string; what: ComponentChildren; shift?: boolean }) {
export function Key({ k, what }: { k: string; what: ComponentChildren }) {
return (
<button type="button" class="key" data-key={k} title={`${keyText(k)}`} onMouseDown={(e) => e.preventDefault()} onClick={(e) => {
<button type="button" class="key" data-key={k} title={keyText(k)} onMouseDown={(e) => e.preventDefault()} onClick={(e) => {
e.stopPropagation();
// A box being typed in (the jump box, the command line) gives the key back to the page.
if ((document.activeElement as HTMLElement | null)?.matches?.("input, textarea")) (document.activeElement as HTMLElement).blur();
press(k, shift);
press(k);
}}
>
<kbd>{keyText(k)}</kbd>
@@ -611,4 +648,3 @@ export function FirstRun() {
</span>
);
}
export const isFirstRun = () => firstRun;
+2 -31
View File
@@ -5,8 +5,6 @@
* have none run a command of the command bar, or copy. Builders are pure: what they need to know
* about the target comes in a context, and how to act in `Act`, so they can be tested without a page.
*/
import { press } from "./press";
export interface Item {
t: "item";
label: string;
@@ -195,7 +193,7 @@ export function nodeEntries(c: NodeCtx, act: Act): Entry[] {
// ---- a pane ----
export interface PaneCtx {
interface PaneCtx {
/** A node's pane: its node; none for an article's. */
node?: NodeCtx;
/** An article's pane: its title. */
@@ -283,7 +281,7 @@ export function topEntries(c: TopCtx, act: Act): Entry[] {
// ---- a row of the libraries panel ----
export interface LibCtx {
interface LibCtx {
title: string;
/** The library this page holds. */
current: boolean;
@@ -302,30 +300,3 @@ export function libraryEntries(c: LibCtx, act: Act): Entry[] {
key(act, "New library…", "n"),
]);
}
/** The page's own `Act`: keys through the key handler, commands through the command bar's handler. */
export function pageAct(hooks: { command(text: string): void; prompt(prefill: string): void }): Act {
return {
press,
command: hooks.command,
prompt: hooks.prompt,
copy(text) {
if (navigator.clipboard) navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
else fallbackCopy(text);
},
};
}
function fallbackCopy(text: string) {
const t = document.createElement("textarea");
t.value = text;
t.style.position = "fixed";
t.style.opacity = "0";
document.body.appendChild(t);
t.select();
try {
document.execCommand("copy");
} finally {
t.remove();
}
}
+2 -1
View File
@@ -22,7 +22,8 @@ export const HELP: [string, [string, string][]][] = [
["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)"],
["Alt+Shift+k j", "in panes: move the active pane up / down its column, as dragging it by its grip or tab does (Alt+Shift+↑ ↓ too; the pane's ⋯ menu offers the same)"],
["[ ]", "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"], ],
["[ ]", "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"],
],
],
[
"Mouse and touch",
+1 -1
View File
@@ -126,7 +126,7 @@ function windowLine(w: PlanWindow, now: Date): string {
}
const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
export interface UsageView {
interface UsageView {
plan: { text: string; title: string; attn: boolean; limited: boolean } | null;
session: { text: string; title: string; calls: number } | null;
}