Public: anyone can read this; the crew can change it.
Talk is keyboard first on a desktop: send, newline, jump to latest and switch conversation, listed under ? #15920
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15816-talk-is-keyboard-first-on-a-desktop-send → main 0 commits fork 3 threads · 3 unresolved
5 files
changed +141
−3
docs/design/areas/talk.md +2
| @@ -63,3 +63,5 @@ On a phone the conversations nav is pinned under the topbar (#14943): New stays | ||
| 63 | 63 | - `.talk-compose` — stays sticky at the bottom of the thread at every size. Prior art: ChatGPT and Claude's composer docked under the reading column. |
| 64 | 64 | |
| 65 | 65 | - `.talk-page` (#15734): the one wrapper around the build box and the shell. From 900 px (56.25rem) up it is a column the height of the screen less the topbar; the shell takes what the box leaves, so the composer is on screen on a first visit. |
| 66 | ||
| 67 | `.talk-keys` is the keyboard help list (#15816): a bordered block above the about line, hidden until `?` is pressed, drawn from `TALK_KEYS`. |
docs/features/talk-keys.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: Keys on the Talk page | |
| 4 | --- | |
| 5 | # Keys on the Talk page | |
| 6 | ||
| 7 | On a desktop, `/talk` is keyboard-first. Press `?` outside the box to open the list of keys; `?` again or `Escape` closes it. | |
| 8 | ||
| 9 | - **Enter** sends, **Shift+Enter** adds a line, **/** goes to the box. | |
| 10 | - **End** (or Ctrl+End), outside the box, jumps to the latest message. Inside the box it moves the caret as usual. | |
| 11 | - **Alt+Up** and **Alt+Down** open the previous or next conversation in the list; the draft is saved first. At the first or last row nothing happens. | |
| 12 | - **Escape** closes the key list when it is open, otherwise it stops the answer. | |
| 13 | - The page draws the list from one constant (`TALK_KEYS`), so the words are written once. | |
| 14 | - The terminal (`ssh ... talk`) is a line prompt: Enter sends, and there is no list to scroll or switch, so these keys have no terminal twin. |
src/web/pages/talk.ts +2 −1
| @@ -67,7 +67,7 @@ import { buildBox, buildCss, chosenTemplate, panelFor } from "../talk_build.ts"; | ||
| 67 | 67 | import { chatBuildOf } from "../../core/chat_build.ts"; |
| 68 | 68 | import { stepOf, repoOf, type Step } from "../../core/talk_steps.ts"; |
| 69 | 69 | import { VIEWS, talkPane, type View } from "./talk_preview.ts"; |
| 70 | import { talkCss, talkJs } from "./talk_client.ts"; | |
| 70 | import { TALK_KEYS, talkCss, talkJs } from "./talk_client.ts"; | |
| 71 | 71 | |
| 72 | 72 | /** A stream lasts this long at most; the client reconnects from its last turn id. */ |
| 73 | 73 | export const STREAM_MS = 40_000; |
| @@ -449,6 +449,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 449 | 449 | </ol> |
| 450 | 450 | <div id="end"></div> |
| 451 | 451 | </div> |
| 452 | <div class="talk-keys" data-keys role="region" aria-label="Keyboard shortcuts" hidden><dl>${TALK_KEYS.map((k) => html`<dt>${k.keys}</dt><dd>${k.does}</dd>`)}</dl></div> | |
| 452 | 453 | ${aboutLine(ctx)} |
| 453 | 454 | ${crewLineHtml(liveCrewRows(ctx, user))} |
| 454 | 455 | <form class="talk-compose" id="compose" method="post" action="${editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}> |
src/web/pages/talk_client.ts +37
| @@ -99,11 +99,31 @@ export const talkCss = /* css */ ` | ||
| 99 | 99 | .talk-replaced { opacity: .55; } |
| 100 | 100 | .talk-failed form { margin-top: 6px; } |
| 101 | 101 | .talk-compose .btn, .talk-suggest .btn, .talk-failed .btn, .talk-act { min-height: 2.75rem; } |
| 102 | .talk-keys { border-bottom: 1px solid var(--border); padding: 0 0 .75rem; } | |
outdated
Principle 6: a 1px border all round is a box around a thing. Use the hairline only where the list ends, or none. |
||
| 103 | .talk-keys[hidden] { display: none; } | |
| 104 | .talk-keys dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; } | |
| 105 | .talk-keys dt { font-weight: 600; } | |
| 106 | .talk-keys dd { margin: 0; } | |
| 102 | 107 | .talk-queued { opacity: .7; } |
| 103 | 108 | .talk-acts { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; } |
| 104 | 109 | .talk-agent .talk-acts { justify-content: flex-start; } |
| 105 | 110 | `; |
| 106 | 111 | |
| 112 | /** | |
| 113 | * The desktop keys (#15816). The page draws its help list from this and the test reads it, so | |
| 114 | * the words are written once. `id` names the binding in the script below. | |
| 115 | */ | |
| 116 | export const TALK_KEYS: readonly { readonly id: string; readonly keys: string; readonly does: string }[] = [ | |
| 117 | { id: "send", keys: "Enter", does: "Send the message" }, | |
| 118 | { id: "newline", keys: "Shift+Enter", does: "Add a line" }, | |
| 119 | { id: "latest", keys: "End or Ctrl+End", does: "Jump to the latest message (outside the box)" }, | |
| 120 | { id: "prev", keys: "Alt+Up", does: "Previous conversation in the list" }, | |
| 121 | { id: "next", keys: "Alt+Down", does: "Next conversation in the list" }, | |
| 122 | { id: "stop", keys: "Escape", does: "Stop the answer, or close this list" }, | |
| 123 | { id: "focus", keys: "/", does: "Go to the box" }, | |
| 124 | { id: "help", keys: "?", does: "Show this list (outside the box)" }, | |
| 125 | ]; | |
| 126 | ||
| 107 | 127 | /** The send button: the bar's one button that is not Stop, Steer or Dictate. */ |
| 108 | 128 | export const sendSelector = ".bar button.btn:not([data-stop]):not([data-steer]):not([data-dictate])"; |
| 109 | 129 | |
| @@ -191,6 +211,23 @@ if (root) { | ||
| 191 | 211 | document.addEventListener("keydown", (e) => { |
| 192 | 212 | if (e.key === "/" && !e.metaKey && !e.ctrlKey && !e.altKey && !/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName) && !document.activeElement.isContentEditable) { e.preventDefault(); box.focus(); } |
| 193 | 213 | }); |
| 214 | // TALK_KEYS. Registered before the Escape-stops listener, so Escape closes the list first. | |
| 215 | const keys = () => root.querySelector("[data-keys]"); | |
| 216 | const typing = () => /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName) || document.activeElement.isContentEditable; | |
| 217 | document.addEventListener("keydown", (e) => { | |
| 218 | if (e.key === "?" && !e.metaKey && !e.ctrlKey && !e.altKey && !typing() && keys()) { e.preventDefault(); keys().hidden = !keys().hidden; return; } | |
| 219 | if (e.key === "Escape" && keys() && !keys().hidden) { e.preventDefault(); e.stopImmediatePropagation(); keys().hidden = true; return; } | |
| 220 | if (e.key === "End" && !e.metaKey && !e.altKey && !e.shiftKey && !typing()) { e.preventDefault(); stuck = true; toEnd(true); return; } | |
| 221 | if ((e.key === "ArrowUp" || e.key === "ArrowDown") && e.altKey && !e.metaKey && !e.ctrlKey && !e.shiftKey) { | |
| 222 | const rows = [...document.querySelectorAll(".talk-chats ul.list:not([aria-label]) > li:not([data-pinned-heading])")].filter((li) => li.querySelector("a")); | |
| 223 | const at = rows.findIndex((li) => li.hasAttribute("aria-current")); | |
| 224 | const to = rows[at + (e.key === "ArrowUp" ? -1 : 1)]; | |
| 225 | if (!to || at < 0) return; | |
| 226 | e.preventDefault(); | |
| 227 | saveDraft(); | |
| 228 | window.location.href = to.querySelector("a").href; | |
| 229 | } | |
| 230 | }); | |
| 194 | 231 | // Links drawn as buttons answer Space as well as Enter. |
| 195 | 232 | root.addEventListener("keydown", (e) => { |
| 196 | 233 | const l = e.key === " " && e.target.closest && e.target.closest("a[data-act]"); |
test/talk-page.test.ts +86 −2
| @@ -328,8 +328,8 @@ describe("the page", () => { | ||
| 328 | 328 | |
| 329 | 329 | test("the page's own bytes are held: stylesheet and script stay small", async () => { |
| 330 | 330 | const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts"); |
| 331 | expect(Buffer.byteLength(talkCss)).toBeLessThan(5_950); | |
| 332 | expect(Buffer.byteLength(talkJs)).toBeLessThan(17_600); | |
| 331 | expect(Buffer.byteLength(talkCss)).toBeLessThan(6_300); | |
| 332 | expect(Buffer.byteLength(talkJs)).toBeLessThan(18_900); | |
| 333 | 333 | say(alice, "agent", "```ts\nlet x = 1;\n```"); |
| 334 | 334 | const page = await get("/talk", alice); |
| 335 | 335 | const size = (await page.arrayBuffer()).byteLength; |
| @@ -544,6 +544,90 @@ describe("the page", () => { | ||
| 544 | 544 | await t.window.happyDOM.close(); |
| 545 | 545 | }); |
| 546 | 546 | |
| 547 | test("desktop keys: ? lists them, End jumps to latest, Escape closes the list before it stops", async () => { | |
| 548 | const t = await boot(); | |
| 549 | t.doc.querySelector("[data-talk]").insertAdjacentHTML("afterbegin", '<div data-keys hidden></div>'); | |
| 550 | const keys = t.doc.querySelector("[data-keys]"); | |
| 551 | const press = (init: object) => { | |
| 552 | const e = new t.window.KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...init }); | |
| 553 | (t.doc.activeElement === t.doc.body ? t.doc : t.doc.activeElement).dispatchEvent(e); | |
| 554 | return e; | |
| 555 | }; | |
| 556 | t.sources.at(-1)!.on["running"]!({ data: "{}" }); | |
| 557 | let scrolled = 0; | |
| 558 | t.doc.getElementById("end").scrollIntoView = () => { scrolled++; }; | |
| 559 | expect(press({ key: "End" }).defaultPrevented).toBe(true); | |
| 560 | expect(scrolled).toBe(1); | |
| 561 | press({ key: "?" }); | |
| 562 | expect(keys.hidden).toBe(false); | |
| 563 | press({ key: "Escape" }); | |
| 564 | expect(keys.hidden).toBe(true); | |
| 565 | expect(t.urls).toEqual([]); | |
| 566 | press({ key: "Escape" }); | |
| 567 | expect(t.urls).toEqual(["/api/v1/conversation/stop"]); | |
| 568 | t.box.focus(); | |
| 569 | expect(press({ key: "?" }).defaultPrevented).toBe(false); | |
| 570 | expect(keys.hidden).toBe(true); | |
outdated
Weak: this only proves the event was prevented. Assert the navigation target, the end-of-list no-op, and that the draft was saved. Also cover End inside the box leaving the caret alone. |
||
| 571 | await t.window.happyDOM.close(); | |
| 572 | }); | |
| 573 | ||
| 574 | test("End inside the box leaves the caret alone and does not scroll", async () => { | |
| 575 | const t = await boot(); | |
| 576 | let scrolled = 0; | |
| 577 | t.doc.getElementById("end").scrollIntoView = () => { scrolled++; }; | |
| 578 | t.box.value = "hello"; | |
| 579 | t.box.focus(); | |
| 580 | t.box.setSelectionRange(2, 2); | |
| 581 | const e = new t.window.KeyboardEvent("keydown", { key: "End", bubbles: true, cancelable: true }); | |
| 582 | t.box.dispatchEvent(e); | |
| 583 | expect(e.defaultPrevented).toBe(false); | |
| 584 | expect(scrolled).toBe(0); | |
| 585 | expect(t.box.selectionStart).toBe(2); | |
| 586 | await t.window.happyDOM.close(); | |
| 587 | }); | |
| 588 | ||
| 589 | test("Alt+Up/Down open the neighbouring conversation after saving the draft, and stop at the ends", async () => { | |
| 590 | const t = await boot(); | |
| 591 | t.doc.body.insertAdjacentHTML("beforeend", '<nav class="talk-chats"><ul class="list"><li><a href="/talk/a">A</a></li><li aria-current="true"><a href="/talk/b">B</a></li><li><a href="/talk/c">C</a></li></ul></nav>'); | |
| 592 | const rows = [...t.doc.querySelectorAll(".talk-chats li")]; | |
| 593 | const went: string[] = []; | |
| 594 | Object.defineProperty(t.window.location, "href", { set: (v: string) => { went.push(v); }, get: () => "http://localhost/talk/b", configurable: true }); | |
| 595 | const press = (init: object) => { | |
| 596 | const e = new t.window.KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...init }); | |
| 597 | t.doc.dispatchEvent(e); | |
| 598 | return e; | |
| 599 | }; | |
| 600 | t.box.value = "unsent words"; | |
| 601 | expect(t.store["talk-draft:u1:c1"]).toBeUndefined(); | |
| 602 | expect(press({ key: "ArrowUp", altKey: true }).defaultPrevented).toBe(true); | |
| 603 | expect(went.at(-1)).toMatch(/\/talk\/a$/); | |
| 604 | expect(JSON.parse(t.store["talk-draft:u1:c1"]!).v).toBe("unsent words"); | |
| 605 | expect(press({ key: "ArrowDown", altKey: true }).defaultPrevented).toBe(true); | |
| 606 | expect(went.at(-1)).toMatch(/\/talk\/c$/); | |
| 607 | rows[1]!.removeAttribute("aria-current"); | |
| 608 | rows[2]!.setAttribute("aria-current", "true"); | |
| 609 | went.length = 0; | |
| 610 | expect(press({ key: "ArrowDown", altKey: true }).defaultPrevented).toBe(false); | |
| 611 | expect(went).toEqual([]); | |
| 612 | press({ key: "ArrowUp" }); | |
| 613 | expect(went).toEqual([]); | |
| 614 | await t.window.happyDOM.close(); | |
| 615 | }); | |
| 616 | ||
| 617 | test("every binding in TALK_KEYS is in the client script and the page's help list names each", async () => { | |
| 618 | const { TALK_KEYS, talkJs } = await import("../src/web/pages/talk_client.ts"); | |
| 619 | const marks: Record<string, string> = { send: '"Enter"', newline: "shiftKey", latest: '"End"', prev: '"ArrowUp"', next: '"ArrowDown"', stop: '"Escape"', focus: '"/"', help: '"?"' }; | |
| 620 | expect(TALK_KEYS.map((k) => k.id).sort()).toEqual(Object.keys(marks).sort()); | |
| 621 | for (const k of TALK_KEYS) expect(talkJs).toContain(marks[k.id]!); | |
| 622 | const res = await get("/talk", alice); | |
| 623 | const html = await res.text(); | |
| 624 | expect(html).toContain("data-keys"); | |
| 625 | for (const k of TALK_KEYS) { | |
| 626 | expect(html).toContain(`<dt>${k.keys}</dt>`); | |
| 627 | expect(html).toContain(k.does.replace(/'/g, "'")); | |
| 628 | } | |
| 629 | }); | |
| 630 | ||
| 547 | 631 | test("the draft is stored per person and conversation after a 300 ms pause, restored on load, cleared on send", async () => { |
| 548 | 632 | const t = await boot("u1"); |
| 549 | 633 | t.box.value = "half"; |
new above
offline
role="dialog"promises focus movement and a close control that are not there. Use a plain region (aria-label, no role dialog). Also add the how-to in docs/features/talk-keys.md.