Public: anyone can read this; the crew can change it.
A search that finds nothing is sent to the crew on Enter #17648
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
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`, | ||
| 12 | 12 | |
| 13 | 13 | 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. |
| 14 | 14 | |
| 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. | |
| 16 | 16 | |
| 17 | 17 | ## Keys beside their actions |
| 18 | 18 |
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 | ||
| 13 | 13 | 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. |
| 14 | 14 | |
| 15 | 15 | 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. | |
src/web/client.ts +19 −7
| @@ -2119,6 +2119,7 @@ ${whichStubJs(whichAsset().path)} | ||
| 2119 | 2119 | var nodes = []; // the rows on screen, in order … |
| 2120 | 2120 | var shown = []; // … and what each one is |
| 2121 | 2121 | var at = 0; |
| 2122 | var picked = false; // a key or the pointer chose the selected row | |
| 2122 | 2123 | |
| 2123 | 2124 | // Every row is built from DOM nodes: the titles are repository names, |
| 2124 | 2125 | // issue titles and lines of code, and page text is exactly what must |
| @@ -2176,6 +2177,7 @@ ${whichStubJs(whichAsset().path)} | ||
| 2176 | 2177 | // starts at the top. |
| 2177 | 2178 | function render(keep) { |
| 2178 | 2179 | armed = null; |
| 2180 | if (!keep) picked = false; | |
| 2179 | 2181 | var q = input.value.trim(); |
| 2180 | 2182 | var pool = palettePool(q, items, served, visits, uses, window.location.pathname, openedAt, VISITS_MAX); |
| 2181 | 2183 | // "#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)} | ||
| 2247 | 2249 | tbox.appendChild(tf); |
| 2248 | 2250 | frag.appendChild(tbox); |
| 2249 | 2251 | } |
| 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 | } | |
| 2251 | 2260 | list.textContent = ''; |
| 2252 | 2261 | list.appendChild(frag); |
| 2253 | 2262 | var n = 0; |
| 2254 | 2263 | 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); | |
| 2256 | 2266 | } |
| 2257 | 2267 | |
| 2258 | 2268 | // The forge's own search, behind the palette. It is the same action as |
| @@ -2290,10 +2300,10 @@ ${whichStubJs(whichAsset().path)} | ||
| 2290 | 2300 | if (k === 'Escape' || ((e.metaKey || e.ctrlKey) && (k === 'k' || k === 'K'))) { |
| 2291 | 2301 | e.preventDefault(); e.stopPropagation(); close(); return; |
| 2292 | 2302 | } |
| 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); } | |
| 2297 | 2307 | else if (k === 'Enter' && (e.metaKey || e.ctrlKey) && shown[at] && shown[at].o) { |
| 2298 | 2308 | e.preventDefault(); |
| 2299 | 2309 | remember(shown[at]); |
| @@ -2302,6 +2312,8 @@ ${whichStubJs(whichAsset().path)} | ||
| 2302 | 2312 | else if (k === 'Enter') { |
| 2303 | 2313 | e.preventDefault(); |
| 2304 | 2314 | 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; } | |
| 2305 | 2317 | if (nodes[at]) nodes[at].click(); |
| 2306 | 2318 | else if (q !== '') location.href = '/search?q=' + encodeURIComponent(q); |
| 2307 | 2319 | } |
| @@ -2344,7 +2356,7 @@ ${whichStubJs(whichAsset().path)} | ||
| 2344 | 2356 | list.onpointermove = function (e) { |
| 2345 | 2357 | var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null; |
| 2346 | 2358 | 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); } | |
| 2348 | 2360 | }; |
| 2349 | 2361 | // A real click and Enter's synthetic one both land here; the browser |
| 2350 | 2362 | // 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 { | ||
| 159 | 159 | return marked && width > 0 && width < 720; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | /** | |
| 163 | * Whether Enter must send nothing (#17647). A list whose only row is "Tell the | |
| 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 | ||
| 162 | 171 | /** A row opened before: where, how it was labelled, how often, and when last. */ |
| 163 | 172 | export interface PaletteUse { |
| 164 | 173 | readonly t: string; |
| @@ -307,4 +316,4 @@ export function palettePool( | ||
| 307 | 316 | * this module before it ever parses it, so `toString` is already the |
| 308 | 317 | * browser's dialect. A test proves the string and the module agree. |
| 309 | 318 | */ |
| 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 { | ||
| 6 | 6 | fuzzyScore, |
| 7 | 7 | paletteHelpersJs, |
| 8 | 8 | rankPalette, |
| 9 | sendsNothing, | |
| 9 | 10 | readUses, |
| 10 | 11 | recordUse, |
| 11 | 12 | recordVisit, |
| @@ -393,3 +394,57 @@ describe("the palette's text is readable (#11028)", () => { | ||
| 393 | 394 | expect(rule('.palette-item[aria-selected="true"] .cat')).toContain("color: var(--fg)"); |
| 394 | 395 | }); |
| 395 | 396 | }); |
| 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 | }); |
new above
offline
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.