Skip to content

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

Open
Zhangbo-cn wants to merge 7 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:feat/shortcuts-registry
Open

Zhangbo-cn wants to merge 7 commits 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

@kunkunblueberry

kunkunblueberry commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

PASS a765e2c

  • One SHORTCUT_COMBOS table is now the single source for tooltips, the help dialog, aria-keyshortcuts and the key handler, replacing four listeners. The reported defect — the dialog advertising Ctrl+, while the handler listened for something else — is exactly what a single table prevents.
  • The comma -> "," mapping is written out rather than derived, with the reason recorded: derivation is what produced a tooltip for a shortcut nobody had wired.
  • The browser test checks agreement between the tooltip, the help row, aria-keyshortcuts and the key that actually fires, and covers the negative cases (typing in a field, a key pressed while a dialog is open). shortcutHints.test.ts pins that every combo has both platform spellings and every handler key has a table entry.
  • The desktop note is measured rather than assumed: menu accelerators double-fire the shortcuts in the packaged Windows build, and that is recorded in the architecture docs in both locales.

Ran: gh pr checks 501 on a765e2c (13/13); read the combo table construction, the matching helper, the new browser script's assertions and the manifest entry.
Not run: the browser lane or shortcutHints.test.ts locally. I did not review every line of the 588-line diff; the review focused on the table, the matcher and the new tests.

dev and others added 6 commits December 5, 2026 06:06
Co-Authored-By: Claude Code <noreply@anthropic.com>
The assistant composer is focused when the app opens, and the hook treated
any focused input or contenteditable as a reason to ignore Ctrl+N, Ctrl+K,
Ctrl+, and Ctrl+J. Those combos all carry a modifier and have no typed
meaning, so only an open dialog and IME composition keep their keys now.

The browser test covers Ctrl+N and Ctrl+J from the focused composer, and
shows that typed text still reaches the project search field.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The app-wide shortcut handler replaced the desktop sidebar's own keydown
listener but routed Ctrl+K to the project picker everywhere, so the
packaged app lost its sidebar search and the desktop smoke failed.

Keep the picker in the browser and open the sidebar search when the
desktop shell is present.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The browser lane now mounts the workspace with the desktop-shell globals
and asserts the key opens the sidebar search instead of the project
picker. At 839412f that assertion fails, which is the failure the
packaged smoke reported on both desktop lanes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 4, 2026
Co-Authored-By: Claude Code <noreply@anthropic.com>

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.

2 participants