Skip to content

[feat] canvas: keep one shortcut list for hints, help and keys - #501

Open
Zhangbo-cn wants to merge 1 commit into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/shortcuts-registry
Open

Zhangbo-cn wants to merge 1 commit into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/shortcuts-registry

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Shortcuts were declared five times: the workspace help dialog listed them by hand, tooltips hardcoded strings like ⌘ ⇧ G, aria-keyshortcuts repeated them again, and four separate keydown listeners decided what the keys did. The copies had already drifted. The help dialog advertised Ctrl+, for model settings while the handler listened for a different key, so the shortcut did nothing while the tooltip promised it worked — reported as "it shows Ctrl+, but the key does not fire".

src/canvas/shortcuts.ts is now the single table: a combo, its macOS and Windows spellings, and the KeyboardEvent.key names it matches. Tooltips, the help dialog, aria-keyshortcuts and the app-wide handler all derive from it. One window listener replaces the four; it ignores keys typed into a field or pressed while a dialog is open, so Escape and text input behave as before.

The comma → "," mapping is explicit rather than derived. Deriving the key name from the combo name is what produced a tooltip promising a shortcut nobody had wired.

docs/architecture/desktop{,.zh-CN}.md now records why the page owns these keys: the packaged Windows build has no menu accelerators, so Ctrl+N, Ctrl+K and Ctrl+J reach the renderer directly, and adding menu accelerators (or an IPC forward) as well would fire each shortcut twice. That was measured on real Windows, not assumed — an earlier version of this branch did call setApplicationMenu with accelerators and double-triggered.

Verification

  • tests/browser/shortcuts.mjs (new, gate lane, isolated fixture): Ctrl+K, Ctrl+,, Ctrl+N, Ctrl+J, Esc, and the negative cases — a key typed into the assistant search box, and a key pressed while a dialog is open. Also asserts the tooltip text, the help dialog row and aria-keyshortcuts agree with the key that actually fires.
  • tests/shortcutHints.test.ts (new): every registered combo has both platform spellings, and every handler key maps to an entry in the table.
  • tsc --noEmit clean, npm test 981 pass / 0 fail, check:i18n 3343 keys 0 problems, check:browser-manifest 94 entries, check:browser-locale 0 problems.
  • apps/desktop is untouched: the probe showed the Electron build needs no menu handling, so none was added.

@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation type:feat New capability or behaviour labels Nov 25, 2026
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch from 7f7407e to 20bfd31 Compare November 25, 2026 03:34
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

First CI run went red on checks / browser (isolated): timeline workflow timed out waiting for the project.create response after clicking "New canvas project".

Cause was mine, not flaky: the new <kbd>Ctrl+N</kbd> hint inside that menu item became part of the item's accessible name ("New canvas project Ctrl+N"), so getByRole("menuitem", { name: "New canvas project", exact: true }) no longer matched — and screen readers would have read the key into the action's name too. The hint is now aria-hidden, like the one the desktop sidebar already shows; aria-keyshortcuts still carries the key for assistive tech.

Re-verified after the fix: timeline_workflow.mjs --full-creation passes locally (it is the only workflow that walks that menu), shortcuts.mjs passes, tsc clean, npm test 981/0.

@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch 2 times, most recently from f8350ca to eba5454 Compare November 25, 2026 09:58
@github-actions github-actions Bot added the area:docs Documentation / 文档 label Nov 25, 2026
@github-actions
github-actions Bot requested a review from wuzhf9 November 25, 2026 09:59
Each panel owned its own copy of the shortcuts: the workspace help dialog listed them by hand, tooltips hardcoded strings like "⌘ ⇧ G", aria-keyshortcuts repeated them again, and four separate keydown listeners decided what the keys did. The copies had already drifted -- the help dialog advertised Ctrl+, for the model settings while the handler listened for a different key, so the shortcut did nothing while the tooltip promised it worked.

src/canvas/shortcuts.ts is now the one table: a combo, its macOS and Windows spellings, and the event names it matches. Tooltips, the help dialog, aria-keyshortcuts and the app-wide handler all read from it, and a unit test fails if a registered combo has no platform spelling or if a handler matches a key the table does not list. One window listener replaces the four: it ignores keys typed into a field or pressed while a dialog is open, so Escape and typing behave as before.

The comma mapping is spelled out rather than derived: the registry names the key "comma" while KeyboardEvent.key is ",". Deriving it is what produced the tooltip that promised a shortcut nobody had wired.

docs/architecture/desktop{,.zh-CN}.md records why the page owns these keys: the packaged Windows build has no menu accelerators, so Ctrl+N, Ctrl+K and Ctrl+J reach the renderer directly, and giving the menu accelerators as well would fire each of them twice.
@Zhangbo-cn
Zhangbo-cn force-pushed the feat/shortcuts-registry branch from eba5454 to a765e2c Compare November 25, 2026 10:06
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

Rebased onto main@b9b7e587; tip is now a765e2cc, 13/13 checks green.

Two conflicts, both in src/canvas/ProjectSelector.tsx, and both were "main added a prop the branch does not know about" rather than disagreeing edits:

  • the props type gained readOnly?: boolean on main exactly where this branch adds openSignal?: number — kept both;
  • the "new project" menu item now has two independent disables, readOnly on main and the aria-keyshortcuts/kbd hint here — kept disabled={readOnly || busy || loading || disabled} with the hint.

Worth stating because the plain-text resolution would have been wrong: dropping readOnly there would have offered "new project" from a read-only project view, and the branch's own diff never saw that prop.

Ran: npx tsc --noEmit; npm test (1000 pass); npm run build; node scripts/check-i18n.mjs (3375 keys, 0 problems); node scripts/check-browser-manifest.mjs (95 entries); plus the release checks above, which include browser (isolated) and the new shortcuts.mjs case
Not run: manual keyboard pass in the packaged desktop build

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:canvas Canvas, nodes and direct manipulation area:docs Documentation / 文档 type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant