diff --git a/.loom/DECISIONS.md b/.loom/DECISIONS.md index 5b283ca..b8e0793 100644 --- a/.loom/DECISIONS.md +++ b/.loom/DECISIONS.md @@ -23,3 +23,9 @@ Current truth belongs in PROJECT.md and linked design documents. This file prese - **`APPIMAGE_EXTRACT_AND_RUN=1` + `NO_STRIP=true` on the linux job.** CI runners can't reliably FUSE-mount linuxdeploy/appimagetool (themselves AppImages); NO_STRIP future-proofs a runner bump to 24.04. Both inert when unnecessary. + +## D-2026-10-18-r30p: 轮盘数字键定案为页内语义:花瓣徽章 1..n 即按键提示(所见即所按),第二页第一个按 1 而非 7——PAGE=6 下全局编号第二页就需要不存在的 10/11/12 键,物理不可行,且 UI_UX_REDESIGN.md 本已声明'数字键 1-6 直选保留'。修复 wheel.js:所有数字键(0-9)一律走花瓣选择分支,超出当前页花瓣数的按键弹出 i18n 提示 wh.keyRange 并 return,不再漏进 query 过滤(原 bug:按 7 会 query+='7' 且 page=0 跳回第一页)。新增 tests/e2e/wheel_page_keys_e2e.py(20 项断言全绿);既有 e2e 26+13+10+22 无回归。 + +- Changed: src/js/wheel.js, src/js/i18n/zh-CN.js, src/js/i18n/en-US.js, tests/e2e/wheel_page_keys_e2e.py +- Affected tasks: +- At: 2026-10-18T11:55:36.073Z diff --git a/src/js/i18n/en-US.js b/src/js/i18n/en-US.js index 40f4fd9..457e4cf 100644 --- a/src/js/i18n/en-US.js +++ b/src/js/i18n/en-US.js @@ -39,6 +39,7 @@ export default { "wh.new": "+ New", "wh.centerHint": "Click to close · right-click/hold = new prompt", "wh.page": "{a}/{b}", + "wh.keyRange": "This page has {n} — press 1–{n} to pick", "wh.envNoBridge": "Runtime problem: Tauri bridge not injected — wheel cannot work", "wh.envAcl": "IPC denied by ACL — capabilities missing, wheel cannot work", diff --git a/src/js/i18n/zh-CN.js b/src/js/i18n/zh-CN.js index 0d52a99..7b53e59 100644 --- a/src/js/i18n/zh-CN.js +++ b/src/js/i18n/zh-CN.js @@ -39,6 +39,7 @@ export default { "wh.new": "+ 新建", "wh.centerHint": "点击关闭 · 右键/长按 = 新建提示词", "wh.page": "{a}/{b}", + "wh.keyRange": "本页只有 {n} 项,按 1–{n} 选择", "wh.envNoBridge": "环境异常:桌面桥接(window.__TAURI__)未注入 — 轮盘无法工作", "wh.envAcl": "IPC 被 ACL 拒绝 — capabilities 缺失,轮盘无法工作", diff --git a/src/js/toast.js b/src/js/toast.js index cda6575..b7262c1 100644 --- a/src/js/toast.js +++ b/src/js/toast.js @@ -3,15 +3,28 @@ import { $, el } from './dom.js'; const ICONS = { ok: 'circle-check', err: 'octagon-alert', warn: 'triangle-alert', info: 'info' }; -export function toast(kind, msg, ms = 2600) { +export function toast(kind, msg, ms = 2600, key = null) { const box = $('#toasts'); if (!box) { console.warn('[toast]', kind, msg); return; } + // keyed toast: a repeated message (e.g. holding an out-of-range digit, whose + // keydown auto-repeat fires dozens of times) replaces the live one instead of + // stacking up — stacked toasts cover the wheel petals and intercept clicks. + if (key) { + const live = box.querySelector(`[data-toast-key="${CSS.escape(key)}"]`); + if (live) { + live.lastElementChild.textContent = msg; + clearTimeout(live._toastTimer); + live._toastTimer = setTimeout(() => { live.style.opacity = '0'; setTimeout(() => live.remove(), 180); }, ms); + return; + } + } const node = el('div', `toast ${kind}`); + if (key) node.dataset.toastKey = key; node.innerHTML = `${icon(ICONS[kind] || 'info', 16)}`; node.lastElementChild.textContent = msg; box.appendChild(node); while (box.children.length > 5) box.firstElementChild.remove(); - setTimeout(() => { node.style.opacity = '0'; setTimeout(() => node.remove(), 180); }, ms); + node._toastTimer = setTimeout(() => { node.style.opacity = '0'; setTimeout(() => node.remove(), 180); }, ms); } // Promise-based confirm modal (replaces native confirm()) diff --git a/src/js/wheel.js b/src/js/wheel.js index 140fdeb..5e8e0a2 100644 --- a/src/js/wheel.js +++ b/src/js/wheel.js @@ -212,13 +212,16 @@ document.addEventListener('keydown', e => { if (e.key === 'Enter') { const el = $$('.petal')[0]; if (el && matches[0]) pick(el, matches[0]); return; } if (e.key === 'ArrowRight' || e.key === 'PageDown') { page++; render(); return; } if (e.key === 'ArrowLeft' || e.key === 'PageUp') { page = Math.max(0, page - 1); render(); return; } - const n = parseInt(e.key, 10); - if (n >= 1 && n <= PAGE && !e.ctrlKey && !e.metaKey && !e.altKey) { + // digits always pick the petal with that badge (page-local 1..matches.length), + // never filter text — out-of-range digits get a hint instead of polluting query + if (/^\d$/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) { + const n = parseInt(e.key, 10); const els = $$('.petal'); - if (matches[n - 1] && els[n - 1]) pick(els[n - 1], matches[n - 1]); + if (n >= 1 && matches[n - 1] && els[n - 1]) { pick(els[n - 1], matches[n - 1]); return; } + if (matches.length) toast('info', t('wh.keyRange', { n: matches.length }), 1400, 'wh.keyRange'); return; } - // typing filter: single printable chars (digits 1-6 are selection keys per design) + // typing filter: single printable chars if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) { query += e.key; page = 0; render(); } diff --git a/src/wheel.css b/src/wheel.css index 7648ae6..6376cf0 100644 --- a/src/wheel.css +++ b/src/wheel.css @@ -68,7 +68,7 @@ body{ .env-err.show{display:grid;padding:24px;background:var(--surface-solid);border:1px solid var(--danger);border-radius:14px;color:var(--text);font-size:11px;line-height:1.6;text-align:center;box-shadow:0 12px 40px rgba(0,0,0,.5)} /* toast inside wheel window */ .toasts{position:fixed;bottom:14px;left:50%;transform:translateX(-50%);z-index:30;display:flex;flex-direction:column;gap:6px;align-items:center} -.toast{background:var(--surface-solid);border:1px solid var(--border-strong);border-radius:10px;padding:9px 16px;font-size:12px;box-shadow:0 8px 30px rgba(0,0,0,.35);animation:open .18s var(--ease-out);display:flex;gap:8px;align-items:center;white-space:nowrap;max-width:290px;overflow:hidden;text-overflow:ellipsis} +.toast{background:var(--surface-solid);border:1px solid var(--border-strong);border-radius:10px;padding:9px 16px;font-size:12px;box-shadow:0 8px 30px rgba(0,0,0,.35);animation:open .18s var(--ease-out);display:flex;gap:8px;align-items:center;white-space:nowrap;max-width:290px;overflow:hidden;text-overflow:ellipsis;pointer-events:none} .toast .ico{flex-shrink:0} .toast.ok .ico{color:var(--success)} .toast.err .ico{color:var(--danger)} .toast.info .ico{color:var(--accent)} @media (prefers-reduced-motion:reduce){*{animation-duration:.01ms!important;transition-duration:.01ms!important}} diff --git a/tests/e2e/wheel_page_keys_e2e.py b/tests/e2e/wheel_page_keys_e2e.py new file mode 100644 index 0000000..5be8614 --- /dev/null +++ b/tests/e2e/wheel_page_keys_e2e.py @@ -0,0 +1,274 @@ +#!/usr/bin/env python3 +"""Wheel pagination hotkey e2e — regression guard for the page-2 digit bug. + +The wheel pages 6 petals at a time and badges each petal with a page-local +digit (1..n). The bug: on page 2 the digits 7/8/9/0 fell through the +selection branch into the typing filter — `query += '7'` plus `page = 0` +snapped the user back to page 1 of a "7"-filtered list. The key contract is +now uniform: every digit key selects the petal showing that badge; a digit +with no petal gets an on-screen hint and NEVER touches the query. + +Covers: + 1. page 1 shows 6 petals badged 1..6, center reads "1/2" + 2. digit 3 on page 1 injects prompt #3 (first-page regression) + 3. ArrowRight -> page 2: petals badged 1..2, center reads "2/2" + 4. digit 1 on page 2 injects global item #7 (badge = key, page-local) + 5. digit 7/8/0 injects nothing, leaves no .filter-tag, shows a range toast + 6. ArrowRight on the last page is a harmless no-op (no crash, no filter) + 7. ArrowLeft returns to page 1 + 8. digit past the visible count on a short page (5 on a 2-petal page) hints + 9. letters still filter (x -> filter-tag, empty-tip), Backspace clears + 10. a digit pressed while the filter has no matches does NOT append to query + +Run: python3 tests/e2e/wheel_page_keys_e2e.py +Reqs: python3 -m playwright (browsers installed) +""" + +import functools +import http.server +import json +import socketserver +import sys +import threading +import time +from pathlib import Path + +from playwright.sync_api import sync_playwright + +SRC = Path(__file__).resolve().parents[2] / "src" + +# 8 pinned prompts; auto wheel sort is frecency-desc, so ids 1..8 map to +# page 1 [1..6] and page 2 [7,8]. No {{vars}} in content -> pick injects +# directly via trigger_wheel_injection. +PROMPTS = [ + {"id": i, "name": f"P{i}", "content": f"body {i}", "tags": [], + "is_pinned": 1, "usage_count": 0, "frecency": 100 - i * 10, + "last_used_at": 1000 - i, "content_type": "text", "variables_json": None, + "app_scopes_json": None, "inject_order": None, + "version": 1, "updated_at": "2026-10-01 10:00"} + for i in range(1, 9) +] + +INIT = """ +localStorage.setItem('pk-lang', 'zh-CN'); +window.__CALLS__ = []; +window.__LISTENERS__ = {}; +window.__TAURI__ = { + core: { + invoke: (cmd, args) => { + window.__CALLS__.push({ cmd, promptId: args && args.promptId }); + switch (cmd) { + case 'get_prompts_view': return Promise.resolve(JSON.parse(JSON.stringify(%s))); + case 'check_service_status': return Promise.resolve(true); + default: return Promise.resolve(null); + } + } + }, + event: { + listen: (name, cb) => { window.__LISTENERS__[name] = cb; return Promise.resolve(() => {}); } + } +}; +""" % json.dumps(PROMPTS) + + +class Quiet(http.server.SimpleHTTPRequestHandler): + def log_message(self, *a): + pass + + +def serve(): + handler = functools.partial(Quiet, directory=str(SRC)) + srv = socketserver.ThreadingTCPServer(("127.0.0.1", 0), handler) + threading.Thread(target=srv.serve_forever, daemon=True).start() + return srv, srv.server_address[1] + + +CHECKS = [] + + +def check(name, cond, extra=""): + CHECKS.append((name, bool(cond), extra)) + print(f" {'PASS' if cond else 'FAIL'} {name}" + (f" [{extra}]" if extra and not cond else "")) + + +def wait_js(page, expr, timeout=5.0): + """Poll `expr` in the page until truthy. More reliable than + wait_for_function on this near-static wheel page, where rAF-driven + polling can stall before first paint.""" + deadline = time.time() + timeout + while time.time() < deadline: + if page.evaluate(expr): + return True + page.wait_for_timeout(40) + return False + + +def show_wheel(page): + page.evaluate("window.__LISTENERS__['wheel-show']()") + page.wait_for_selector("#wheel.show .petal") + + +def petal_names(page): + return page.eval_on_selector_all("#wheel .petal .pn", "els => els.map(e => e.textContent)") + + +def petal_badges(page): + return page.eval_on_selector_all("#wheel .petal .k", "els => els.map(e => e.textContent)") + + +def inject_calls(page): + return page.evaluate("window.__CALLS__.filter(c => c.cmd === 'trigger_wheel_injection')") + + +def wait_inject(page, n): + assert wait_js( + page, f"window.__CALLS__.filter(c => c.cmd === 'trigger_wheel_injection').length === {n}") + + +def center_text(page): + return page.locator("#centerTxt").text_content() or "" + + +def main(): + srv, port = serve() + with sync_playwright() as p: + browser = p.chromium.launch() + page = browser.new_page() + page.add_init_script(INIT) + page.goto(f"http://127.0.0.1:{port}/wheel.html") + assert wait_js(page, "!!(window.__LISTENERS__ && window.__LISTENERS__['wheel-show'])") + + # ---- 1. open -> page 1, six petals badged 1..6 ---- + show_wheel(page) + check("page 1: six petals", len(petal_names(page)) == 6, str(petal_names(page))) + check("page 1: badges 1..6", petal_badges(page) == ["1", "2", "3", "4", "5", "6"], + str(petal_badges(page))) + check("page 1: names P1..P6 (frecency order)", + petal_names(page) == ["P1", "P2", "P3", "P4", "P5", "P6"], str(petal_names(page))) + check("page 1: center shows 1/2", "1/2" in center_text(page), center_text(page)) + + # ---- 2. first-page regression: digit 3 picks P3 ---- + page.keyboard.press("3") + wait_inject(page, 1) + calls = inject_calls(page) + check("digit 3 on page 1 injects P3", calls[-1]["promptId"] == 3, str(calls)) + page.wait_for_timeout(350) # let hide() settle before re-showing + + # ---- 3. ArrowRight -> page 2 shows badges 1..2 (page-local) ---- + show_wheel(page) + page.keyboard.press("ArrowRight") + assert wait_js(page, "document.querySelectorAll('#wheel .petal').length === 2") + check("page 2: two petals P7,P8", petal_names(page) == ["P7", "P8"], str(petal_names(page))) + check("page 2: badges are page-local 1,2", petal_badges(page) == ["1", "2"], + str(petal_badges(page))) + check("page 2: center shows 2/2", "2/2" in center_text(page), center_text(page)) + + # ---- 4. digit 1 on page 2 picks the FIRST petal of page 2 (P7) ---- + page.keyboard.press("1") + wait_inject(page, 2) + calls = inject_calls(page) + check("digit 1 on page 2 injects P7 (badge=key)", + calls[-1]["promptId"] == 7, str(calls)) + page.wait_for_timeout(350) + + # ---- 5. digits 7/8/0 never select and never pollute the filter ---- + show_wheel(page) + page.keyboard.press("ArrowRight") + assert wait_js(page, "document.querySelectorAll('#wheel .petal').length === 2") + before = len(inject_calls(page)) + for key in ("7", "8", "0"): + page.keyboard.press(key) + page.wait_for_timeout(120) + check("digits 7/8/0 inject nothing", len(inject_calls(page)) == before, + str(inject_calls(page))) + check("digits 7/8/0 leave no filter-tag", + page.locator("#wheel .filter-tag").count() == 0) + check("digits 7/8/0 keep page 2 rendered", + petal_names(page) == ["P7", "P8"], str(petal_names(page))) + check("out-of-range digit shows range hint toast", + page.locator("#toasts .toast").count() >= 1 + and "1–2" in (page.locator("#toasts").text_content() or ""), + page.locator("#toasts").text_content() or "") + check("still on page 2 after stray digits", "2/2" in center_text(page), + center_text(page)) + + # ---- 5b. holding an out-of-range digit must NOT stack toasts ---- + # Regression guard for Devin Review on PR #18: keydown auto-repeat used + # to spawn one toast per repeat (up to 5), and the stacked toasts sit + # over the lower petals with pointer events enabled -> clicks hit a + # toast instead of selecting a prompt. Keyed toasts coalesce into one. + page.keyboard.down("7") + page.wait_for_timeout(700) # let OS key-repeat fire + page.keyboard.up("7") + page.wait_for_timeout(120) + n_toasts = page.locator("#toasts .toast").count() + check("held out-of-range digit coalesces to one toast", n_toasts == 1, + f"toasts={n_toasts}") + check("toast does not intercept petal clicks", + "none" == page.evaluate( + "() => getComputedStyle(" + "document.querySelector('#toasts .toast')).pointerEvents"), + page.evaluate( + "() => getComputedStyle(" + "document.querySelector('#toasts .toast')).pointerEvents")) + + # ---- 6. ArrowRight on last page: no crash, no wrap, no filter ---- + page.keyboard.press("ArrowRight") + page.wait_for_timeout(120) + check("last-page ArrowRight is a no-op", + petal_names(page) == ["P7", "P8"] and "2/2" in center_text(page) + and page.locator("#wheel .filter-tag").count() == 0, + f"{petal_names(page)} {center_text(page)}") + + # ---- 7. ArrowLeft returns to page 1 ---- + page.keyboard.press("ArrowLeft") + assert wait_js(page, "document.querySelectorAll('#wheel .petal').length === 6") + check("ArrowLeft back to page 1", "1/2" in center_text(page) + and petal_names(page) == ["P1", "P2", "P3", "P4", "P5", "P6"], + f"{petal_names(page)} {center_text(page)}") + + # ---- 8. digit past visible count on a short page still hints ---- + page.keyboard.press("ArrowRight") + assert wait_js(page, "document.querySelectorAll('#wheel .petal').length === 2") + n_toasts = page.locator("#toasts .toast").count() + n_inject = len(inject_calls(page)) + page.keyboard.press("5") + page.wait_for_timeout(120) + # wave44-review: a keyed toast REPLACES the live one instead of stacking, + # so the count may stay flat — assert the hint is present and correct + # (and still nothing injected), not that the stack grew. + check("digit 5 on 2-petal page hints, does not inject", + len(inject_calls(page)) == n_inject + and "1–2" in (page.locator("#toasts").text_content() or ""), + page.locator("#toasts").text_content() or "") + + # ---- 9. letters still filter; 10. digit never appends to query ---- + page.keyboard.press("x") # zero matches -> empty-tip, petals gone + page.wait_for_selector("#wheel .empty-tip") + check("letter x filters (filter-tag shown)", + "x" in (page.locator("#wheel .filter-tag").text_content() or "")) + before_q = page.locator("#wheel .filter-tag").text_content() + page.keyboard.press("9") + page.wait_for_timeout(120) + check("digit 9 does not append to query", + (page.locator("#wheel .filter-tag").text_content() or "") == before_q, + page.locator("#wheel .filter-tag").text_content() or "") + page.keyboard.press("Backspace") + assert wait_js(page, "document.querySelectorAll('#wheel .petal').length === 6") + check("Backspace clears filter back to page 1", + petal_names(page) == ["P1", "P2", "P3", "P4", "P5", "P6"], + str(petal_names(page))) + + browser.close() + srv.shutdown() + + failed = [n for n, ok, _ in CHECKS if not ok] + print(f"\n{len(CHECKS) - len(failed)}/{len(CHECKS)} checks passed") + if failed: + print("FAILED:", ", ".join(failed)) + sys.exit(1) + print("ALL PASS") + + +if __name__ == "__main__": + main()