Skip to content

fix(ui): restore the digit shortcut for the settings view - #182

Merged
argszero merged 1 commit into
mainfrom
fix/nav-keyboard-shortcut-range
Sep 12, 2026
Merged

argszero merged 1 commit into
mainfrom
fix/nav-keyboard-shortcut-range

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

The sidebar advertises a digit shortcut on every nav item, but the global keydown guard hard-coded the range 1-7. NAV_ORDER now has 8 items (ops was inserted before settings), so settings renders the badge "8" and its tooltip says to press it — while pressing 8 is silently ignored. The view was unreachable by digit key while advertising that it was reachable.

ui/README.md documented 1-7 correctly: it was a faithful description of a buggy guard, not a doc drift. Provenance: ad631ae (#44) wrote the range when NAV had exactly 7 items; 85982e8 (#80) inserted ops before settings and the range was never widened.

Related Issue

Changes

  • ui/js/app.js: the digit guard no longer writes a bound at all — the badge is NAV_ORDER index + 1 and the handler resolves the item from the same array, so an out-of-range digit is a no-op and badge/key range can never diverge again. (Simply bumping "7""8" would re-arm the identical bug at the next view insertion; the controls below demonstrate exactly that.)
  • ui/js/app.js: help-panel key row 1–71–8; the two comments that asserted 1-7 now state the count-independent rule (1..N, N = NAV_ORDER.length).
  • ui/css/style.css: comment 数字 1-7 切换视图数字键切换视图.
  • ui/README.md: 1-71-8 (view list corrected to all 8 in NAV_ORDER order); help row 1–71–8; kbd-guard line de-numbered. Plus 4 more stale current-state counts from the same sweep, each against an arbiter that is itself asserted:
    • language-pack keys 733785 (src/i18n_pack.rs ZH_KEY_COUNT/EN_KEY_COUNT, enforced by cargo test)
    • referenced-key scan 496680 (T() literals 430 + data-i18n* 305, deduplicated)
    • toast() call sites 3975
    • document.title coverage 7 个视图8 (VIEW_TITLE has 8 keys)
  • ui/index.html: cache-bust 20260912-320260912-4 (5 refs).
  • 涉及配置/数据结构的改动已同步示例文件 — N/A: no config or schema change.

No i18n key change: help.k2's value is range-free in both packs (切换侧边栏视图 / Switch sidebar view), so no pack edit and no gate-constant change was needed.

Tests

  • cargo test 全部通过 — 165 passed / 0 failed
  • cargo fmt --check 通过
  • cargo clippy --all-targets -- -D warnings 通过
  • node --check ui/js/app.js 通过
  • 新增/更新了单元测试(如适用) — not applicable: the change is in ui/ JS, which has no test harness in this repo; the i18n/key gates (src/i18n_pack.rs) still pass unchanged. Verification was done with an A/B probe over the real sources instead:
    • guard range read out of the source and evaluated against synthetic key events (the probe does not look for the literal 7/8, so it stays valid after the guard is rewritten)
    • before (HEAD): RESULT: FAIL (1 advertised shortcut(s) do nothing), exit 1 → after: RESULT: OK (every advertised shortcut works), exit 0
    • controls: hard-coding "7" on the fixed tree reproduces the failure; hard-coding "8" also fails once a 9th view is added, while the derived guard passes in the same 9-view tree — i.e. the fix removes the class, not the instance

Checklist

  • 分支命名符合约定 (fix/)
  • Commit message 使用 Conventional Commits 格式 (fix(ui): …)
  • 单一职责,改动最小化 — one defect (the digit shortcut) + the same-file claim refresh found by the same sweep; no opportunistic refactor

The sidebar advertises a digit key on every nav item, but the keydown guard
hard-coded the range `1`-`7`. `NAV_ORDER` has 8 items (`ops` was inserted
before `settings`), so `settings` renders the badge "8" and its tooltip tells
the user to press it -- while pressing 8 is silently ignored. The doc in
`ui/README.md` documented `1-7` correctly: it was a faithful description of a
buggy guard.

The guard no longer writes a bound at all: the badge is `NAV_ORDER` index + 1
and the handler now resolves the item from the same array, so an out-of-range
digit is a no-op and the two can never diverge again (bumping "7" to "8" would
only re-arm the same bug at the next view insert).

Also refresh five stale current-state claims in `ui/README.md` that the same
sweep found, each against an arbiter that is itself asserted: language-pack key
count 733 -> 785 (`src/i18n_pack.rs` constants), the referenced-key union
496 -> 680 (T() literals 430 + data-i18n 305), toast() call sites 39 -> 75,
view count 7 -> 8 (`VIEW_TITLE`), and the help row `1-7` -> `1-8`.

Tests: cargo test 165 passed; fmt and clippy -D warnings clean; node --check
clean; A/B probe over the real sources flips FAIL(exit 1) -> OK(exit 0), with
controls showing a hard-coded "8" still breaks once a 9th view is added.
@argszero
argszero merged commit 75aa3b3 into main Sep 12, 2026
1 check passed
@argszero
argszero deleted the fix/nav-keyboard-shortcut-range branch September 12, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant