Public: anyone can read this; the crew can change it.

A search that finds nothing is sent to the crew on Enter #17648

opened this in answer to

Merged 20h 50m ago, live in production

mason/forge:mason/17647-a-search-that-finds-nothing-is-sent-to-t → main 0 commits fork 5 threads · 5 unresolved

  • Merged. mason/17647-a-search-that-finds-nothing-is-sent-to-t was merged into main as bd828f9.

Review

Sign in to review this change.
5 files changed +89 −9
docs/design/areas/palette.md +1 −1
@@ -12,7 +12,7 @@ The command palette is the keyboard-first fuzzy-find overlay (`⌘K` / `Ctrl K`,
1212
1313 Dismissal and the phone: a click or tap on the backdrop closes the palette (a drag that began inside does not), and the page behind does not scroll. Under 720px the dialog is a sheet pinned to the top of the visual viewport (`--vv-top`, `--vv-h`, set by `openPalette()`), so the keyboard shrinks it; the input is 16px, rows 44px, and the foot trades its key hints for a link-variant `[data-palette-close]` button. No new class.
1414
15 The palette's tell row (`data-tell`, last in the list) sends the typed sentence to `/tell`. Its answer is one `.toast[data-palette-tell]` at the top of `#main`, drawn by `tellFromHere()` in `src/web/client.ts` from existing parts only: `.toast` and `.toast-body`, a link-variant small `.btn` as the dismiss ×, and focus moved to the toast (`tabindex="-1"`, `role="status"`) because the palette that held it has just closed. It clears itself after 12 seconds. No new component class.
15 The palette's tell row (`data-tell`, last in the list) sends the typed sentence to `/tell`. Its answer is one `.toast[data-palette-tell]` at the top of `#main`, drawn by `tellFromHere()` in `src/web/client.ts` from existing parts only: `.toast` and `.toast-body`, a link-variant small `.btn` as the dismiss ×, and focus moved to the toast (`tabindex="-1"`, `role="status"`) because the palette that held it has just closed. When the words match nothing, the tell row is the only row: it is not selected, Enter sends nothing, and a `.palette-empty` note says there is no match; an arrow key or a tap chooses the row (#17647). It clears itself after 12 seconds. No new component class.
1616
1717 ## Keys beside their actions
1818
docs/features/palette-rows.md +4
@@ -13,3 +13,7 @@ Terminal: the palette itself is a web surface, but its app actions have their do
1313 The cap of eight apps: two rows an app, so at most sixteen rows, about one screen of the list; the page lists thirty repositories and a palette is a short list, not a table.
1414
1515 Tests: `test/palette-rows.test.ts`.
16
17 ## A search that matches nothing sends nothing (#17647)
18
19 When the typed words match no row, "Tell the crew: <words>" is the only row left. It stays in the list but is not selected: Enter does nothing and the list says "No matches." (`sendsNothing`, `src/web/palette.ts`). An arrow key, hover or a tap chooses the row, and then it asks its usual confirmation. Words with a match still go to the first result. The terminal has no palette: nothing there changes.

Non-blocking: 'then it asks its usual confirmation' contradicts the PR note that the tell row sends straight away once chosen. Reword to match what the code does.

src/web/client.ts +19 −7
@@ -2119,6 +2119,7 @@ ${whichStubJs(whichAsset().path)}
21192119 var nodes = []; // the rows on screen, in order …
21202120 var shown = []; // … and what each one is
21212121 var at = 0;
2122 var picked = false; // a key or the pointer chose the selected row
21222123
21232124 // Every row is built from DOM nodes: the titles are repository names,
21242125 // issue titles and lines of code, and page text is exactly what must
@@ -2176,6 +2177,7 @@ ${whichStubJs(whichAsset().path)}
21762177 // starts at the top.
21772178 function render(keep) {
21782179 armed = null;
2180 if (!keep) picked = false;
21792181 var q = input.value.trim();
21802182 var pool = palettePool(q, items, served, visits, uses, window.location.pathname, openedAt, VISITS_MAX);
21812183 // "#123" on a repository's page: that number, built here from the page's own path (the server read no issue for it).
@@ -2247,12 +2249,20 @@ ${whichStubJs(whichAsset().path)}
22472249 tbox.appendChild(tf);
22482250 frag.appendChild(tbox);
22492251 }
2250 if (nodes.length === 0) frag.appendChild(emptyLine(q));
2252 // Words that match nothing leave only the tell row: it is not selected
2253 // for Enter, and the list says there is no match (#17647).
2254 var lone = sendsNothing(shown, picked);
2255 if (nodes.length === 0 || lone) {
2256 var note = emptyLine(q);
2257 note.setAttribute('role', 'status');
2258 frag.insertBefore(note, frag.firstChild);
2259 }
22512260 list.textContent = '';
22522261 list.appendChild(frag);
22532262 var n = 0;
22542263 if (was) nodes.forEach(function (a, i) { if (a.getAttribute('href') === was) n = i; });
2255 select(n, false);
2264 if (lone) { at = 0; input.removeAttribute('aria-activedescendant'); }
2265 else select(n, false);
outdated

select(n, false) selects the row and this block then undoes it. Skip the selection when lone is true. Also add a test for this wiring, since only enterAction is tested.

22562266 }
22572267
22582268 // The forge's own search, behind the palette. It is the same action as
@@ -2290,10 +2300,10 @@ ${whichStubJs(whichAsset().path)}
22902300 if (k === 'Escape' || ((e.metaKey || e.ctrlKey) && (k === 'k' || k === 'K'))) {
22912301 e.preventDefault(); e.stopPropagation(); close(); return;
22922302 }
2293 if (k === 'ArrowDown') { e.preventDefault(); select(at + 1); }
2294 else if (k === 'ArrowUp') { e.preventDefault(); select(at - 1); }
2295 else if (k === 'Home') { e.preventDefault(); select(0); }
2296 else if (k === 'End') { e.preventDefault(); select(nodes.length - 1); }
2303 if (k === 'ArrowDown') { e.preventDefault(); picked = true; select(at + 1); }
2304 else if (k === 'ArrowUp') { e.preventDefault(); picked = true; select(at - 1); }
2305 else if (k === 'Home') { e.preventDefault(); picked = true; select(0); }
2306 else if (k === 'End') { e.preventDefault(); picked = true; select(nodes.length - 1); }
22972307 else if (k === 'Enter' && (e.metaKey || e.ctrlKey) && shown[at] && shown[at].o) {
22982308 e.preventDefault();
22992309 remember(shown[at]);
@@ -2302,6 +2312,8 @@ ${whichStubJs(whichAsset().path)}
23022312 else if (k === 'Enter') {
23032313 e.preventDefault();
23042314 var q = input.value.trim();
2315 // Nothing is sent for a lone tell row: the list already says so.
2316 if (sendsNothing(shown, picked)) { e.stopPropagation(); return; }
23052317 if (nodes[at]) nodes[at].click();
23062318 else if (q !== '') location.href = '/search?q=' + encodeURIComponent(q);
23072319 }
outdated

Empty branch holding only a comment. Use a guard (if (what !== 'nomatch') { ... }) so the no-op needs no placeholder.

@@ -2344,7 +2356,7 @@ ${whichStubJs(whichAsset().path)}
23442356 list.onpointermove = function (e) {
23452357 var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null;
23462358 var i = a ? nodes.indexOf(a) : -1;
2347 if (i !== -1 && i !== at) select(i, false);
2359 if (i !== -1 && i !== at) { picked = true; select(i, false); }
23482360 };
23492361 // A real click and Enter's synthetic one both land here; the browser
23502362 // follows the link (and honours a modifier) on its own.
src/web/palette.ts +10 −1
@@ -159,6 +159,15 @@ export function opensAsSheet(marked: boolean, width: number): boolean {
159159 return marked && width > 0 && width < 720;
160160 }
161161
162 /**
163 * Whether Enter must send nothing (#17647). A list whose only row is "Tell the
outdated

Orphaned doc comment: 'A row opened before…' now sits above enterAction's own comment and no longer documents PaletteUse. Move enterAction away from the interface.

164 * crew" means the words matched nothing: Enter must not hand a search to the
165 * crew, so it waits until a key or the pointer has chosen that row (`picked`).
166 */
167 export function sendsNothing(shown: readonly { h: string }[], picked: boolean): boolean {
168 return !picked && shown.length === 1 && shown[0]!.h === "#tell";
169 }
170
outdated

The 'search' return value is never read by the client. Return a boolean or use it; do not keep a dead variant.

162171 /** A row opened before: where, how it was labelled, how often, and when last. */
163172 export interface PaletteUse {
164173 readonly t: string;
@@ -307,4 +316,4 @@ export function palettePool(
307316 * this module before it ever parses it, so `toString` is already the
308317 * browser's dialect. A test proves the string and the module agree.
309318 */
310 export const paletteHelpersJs = `${fuzzyScore.toString()}\n${rankPalette.toString()}\n${opensAsSheet.toString()}\n${frecencyOrder.toString()}\n${readUses.toString()}\n${recordUse.toString()}\n${recordVisit.toString()}\n${visitRows.toString()}\n${visitLoad.toString()}\n${palettePool.toString()}`;
319 export const paletteHelpersJs = `${fuzzyScore.toString()}\n${rankPalette.toString()}\n${opensAsSheet.toString()}\n${sendsNothing.toString()}\n${frecencyOrder.toString()}\n${readUses.toString()}\n${recordUse.toString()}\n${recordVisit.toString()}\n${visitRows.toString()}\n${visitLoad.toString()}\n${palettePool.toString()}`;
test/palette.test.ts +55
@@ -6,6 +6,7 @@ import {
66 fuzzyScore,
77 paletteHelpersJs,
88 rankPalette,
9 sendsNothing,
910 readUses,
1011 recordUse,
1112 recordVisit,
@@ -393,3 +394,57 @@ describe("the palette's text is readable (#11028)", () => {
393394 expect(rule('.palette-item[aria-selected="true"] .cat')).toContain("color: var(--fg)");
394395 });
395396 });
397
398 describe("a search that matches nothing (#17647)", () => {
399 test("only a lone tell row, not yet chosen, sends nothing", () => {
400 const tell = { h: "#tell" };
401 expect(sendsNothing([tell], false)).toBe(true);
402 expect(sendsNothing([tell], true)).toBe(false);
403 expect(sendsNothing([{ h: "/a" }, tell], false)).toBe(false);
404 expect(sendsNothing([], false)).toBe(false);
405 });
406
407 test("in the running palette: no row selected, a note, Enter sends nothing, ArrowDown then Enter reaches the tell row", async () => {
408 const { Window } = await import("happy-dom");
409 const win = new Window({ url: "http://forge.test/search" });
410 const index = JSON.stringify({ items: [{ t: "Page a", h: "/a" }], tell: { app: "demo" } });
411 win.document.body.innerHTML = `<script type="application/json" id="palette-index">${index}</script>
412 <dialog class="dialog palette" id="palette"><input class="input palette-input" type="text" /><div class="palette-list" id="palette-list"></div></dialog>`;
413 (win.HTMLElement.prototype as any).scrollIntoView ??= () => {};
414 let onFetch: () => void = () => {};
415 const sent: string[] = [];
416 let lookedUp!: Promise<void>;
417 lookedUp = new Promise<void>((done) => { onFetch = done; });
418 new Function("document", "window", "location", "sessionStorage", "CSS", "fetch", "EventSource", shellJs)(
419 win.document, win, win.location, win.sessionStorage, { escape: (x: string) => x },
420 async (url: string) => { sent.push(String(url)); onFetch(); return { ok: false, status: 500, text: async () => "", headers: { get: () => null } }; },
421 undefined,
422 );
423 const doc = win.document as any;
424 doc.dispatchEvent(new win.KeyboardEvent("keydown", { key: "k", ctrlKey: true, bubbles: true, cancelable: true }));
425 const input = doc.querySelector(".palette-input");
426 input.value = "zzq colour wheel";
427 input.dispatchEvent(new win.Event("input", { bubbles: true }));
428 const key = (k: string) => doc.querySelector("#palette").dispatchEvent(new win.KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
429 const rows = () => [...doc.querySelectorAll(".palette-item")];
430 // The server lookup is debounced: wait for its request, then let its answer (nothing) land.
431 await lookedUp;
432 for (let i = 0; i < 10; i++) await Promise.resolve();
433
434 expect(rows().length).toBe(1);
435 expect(rows()[0].getAttribute("data-tell")).toBe("zzq colour wheel");
436 expect(rows()[0].getAttribute("aria-selected")).toBe("false");
437 expect(input.hasAttribute("aria-activedescendant")).toBe(false);
438 expect(doc.querySelector(".palette-empty")?.textContent).toContain("No matches");
439
440 const tells = () => sent.filter((u) => u.includes("/tell"));
441 key("Enter");
442 expect(tells()).toEqual([]);
443 expect(doc.querySelector("#palette").hasAttribute("open")).toBe(true);
444
445 key("ArrowDown");
446 expect(rows()[0].getAttribute("aria-selected")).toBe("true");
447 key("Enter");
448 expect(tells().length).toBe(1);
449 });
450 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs