Repository navigation
Studio: match letter shortcuts by the letter the layout types - #14113
danielhanchen merged 11 commits into
Conversation
Some WebKit/Electron builds omit the scrollbarGutter computed style, which crashed the Mac desktop app on startup when aligning the composer dock.
Use the Keyboard Layout API when available so Settings and sidebar hints name the keys users see on Dvorak and other layouts while bindings stay on KeyboardEvent.code.
Shortcuts were matched on KeyboardEvent.code, the QWERTY position, so on Dvorak Ctrl+X (the B position) toggled the sidebar instead of cutting and Ctrl+Z (the Slash position) opened the shortcuts list instead of undoing, while the labels named the QWERTY cap. A key that types a Latin letter now answers as that letter, and a letter position typing punctuation as that punctuation, both when matching and when recording, so labels name the key pressed in every browser. Digits, other punctuation, the keypad, non-Latin layouts and Option on macOS keep their position. US QWERTY is unchanged. Replaces the Keyboard Layout API labels, which Firefox and Safari do not implement and which left the chords themselves positional. [skip ci]
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 225dea2280
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ): boolean { | ||
| const code = event.code || keyToCode(event.key ?? ""); | ||
| if (code !== binding.code) return false; | ||
| if (eventCode(event, mac) !== binding.code) return false; |
There was a problem hiding this comment.
Preserve persisted physical-code overrides
When a Dvorak user upgrades with an existing custom letter chord, the stored value was produced by the old bindingFromEvent from event.code; for example, pressing the key that types B stored Mod+KeyN, and the old matcher fired on that physical key. loadOverrides reloads the same string without a semantics version or migration, but this comparison now treats it as logical N, so the shortcut silently moves to another key. Version or migrate legacy entries (or retain legacy matching for them) so existing custom shortcuts keep working.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: only non-QWERTY users with custom letter chords are affected, a stored value cannot say which layout recorded it, and Settings already labelled those chords by the key that now fires them, which is the mismatch this issue reports.
| const typed = keyToCode(key); | ||
| if (typed !== key) return typed; |
There was a problem hiding this comment.
Normalize shifted punctuation on remapped letter keys
On Dvorak, Shift+KeyW reports <; because keyToCode recognizes only the unshifted ,, this branch falls through to KeyW, while Shift+Comma types W and is also normalized to KeyW. As a result, recording Ctrl+Shift+< is saved and labeled as Ctrl+Shift+W, both physical keys trigger any Shift+KeyW binding, and Shift+Comma is unreachable. Map shifted symbols to their base punctuation codes while retaining the Shift modifier.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: no shipped default uses Shift with those keys, and mapping the US shifted symbols misroutes other layouts (AZERTY types ? with Shift on its comma key), so Shift chords there stay positional as on main.
Dvorak types "/" on the [ position and z on the / one, so matching letters by the letter typed left Mod+Slash with no key. A punctuation position now also matches the punctuation it types; recording still keeps the position, so German's Ctrl+- keeps its Mod+Slash and the zoom chords still yield. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f558e55f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| eventCode(event, mac) !== binding.code && | ||
| typedPunctuation(event, mac) !== binding.code |
There was a problem hiding this comment.
Enforce registry ownership for punctuation aliases
On a layout where a punctuation character sits on a different punctuation position (standard Dvorak's Ctrl+/ emits code: "BracketLeft" and key: "/"), this fallback makes the event match both Mod+Slash and a user-recorded Mod+BracketLeft. findConflicts and shortcutOwningBinding compare only serialized strings, so both handlers register with no conflict warning; the first mounted listener prevents the other, making the winner depend on component/route mount order. Resolve ownership across every binding that matches the event rather than treating these aliases as independent chords.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs a Dvorak user to record a custom Mod+BracketLeft (no shipped default uses it), and recording by the typed punctuation instead would make Mod+Slash unreachable on German and other layouts that type / with Shift.
| mac = isMacPlatform(), | ||
| ): ShortcutBinding | null { | ||
| const code = event.code || keyToCode(event.key ?? ""); | ||
| const code = eventCode(event, mac); |
There was a problem hiding this comment.
Include punctuation aliases in keystroke search
On standard Dvorak, the actual Ctrl+/ keydown is accepted as Mod+Slash only by typedPunctuation, but this recorder returns Mod+BracketLeft; the Settings by-keystroke path passes that value to exact-code keystrokeMatchesBinding. Consequently, pressing the chord that really runs openKeyboardShortcuts does not include that action in search results. Preserve the event's punctuation alias for search, or compare search input with the same matching semantics.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the chord itself works; only search-by-keystroke for Ctrl+/ on Dvorak misses the row, which is still found by name, and the recorder keeps positions for the reason above.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The layout-aware matcher adds 328 B raw / 99 B transfer to the eager startup JS (one machine and build, chunk count unchanged); it runs on every keydown from the first screen, so there is nothing to lazy-load.
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
|
The new |
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
…eset the startup budget to the build (#14168) ## Summary Main is over the startup bundle budget, so `Frontend build + bundle sanity` fails on every PR based on it: ``` over the startup budget: transfer 2005.9 KB > 2003.5 KB, raw 6665.4 KB > 6659.1 KB (main at 2fee36f) ``` This PR takes two steps. It moves #14137's prompt upsampler client out of the startup chunks, which is real growth with a lazy home. It then resets both limits to the measured build. Main has gone over this budget repeatedly, and the root of that is a shortfall in how the limits were raised, which this corrects. ## Cause **#14137 (FLUX.3 prompt upsampling).** The Images page is lazy (`ImagesPage = lazy(...)` in `__root.tsx`), but `features/images/api.ts` is not. Startup modules import it for other calls (`loaded-models-api.ts`, `loaded-models-sources.ts`, `use-media-companion-bytes.ts`). #14137 put the four upsampler calls there, with value imports from `lib/prompt-enhance.ts`, so that module joined the startup chunks. Only `prompt-enhance-panel.tsx`, inside the lazy Images page, calls them. **The limits themselves.** Each raise since #14073 was sized from its own PR's delta and added to the previous limit. That previous limit already sat below the build, starting at #14073: - `475a02ac` measures 2,047,700 B transfer against the 2,047,608 B limit #14073 set. - By `2fee36ff` the gap is 6,500 B raw and 2,409 B transfer. The raises since (#14072, #14075, #14110, #14108, #14113) each added their delta, so the shortfall carried forward. CI agrees with my machine to the byte: the first run of this PR read 1999.7 KB transfer on both. ## Change - **New `features/images/prompt-upsampler-api.ts`:** holds `getPromptUpsamplerStatus`, `startPromptUpsamplerDownload`, `cancelPromptUpsamplerDownload` and `previewEnhancedPrompt`, moved unchanged, with the same `parseJson` error handling. - **`api.ts`:** now imports only the `PromptEnhancement` type from `lib/prompt-enhance` (erased at build). - **`prompt-enhance-panel.tsx`:** imports the calls from the new module. - **No behavior change** in the app. - **`check-bundle-budget.ts`:** both limits are reset to the measured build plus the usual margin (160 B raw, 189 B transfer), with an entry in the BUDGET comment block explaining why the reset is absolute rather than by delta. - `rawBytes`: 6,819,206 (main after #14113) -> 6,825,885. - `transferBytes`: 2,051,727 -> 2,054,261. ## Testing One machine and build, Node 24, exact byte totals from the budget script, 95 chunks throughout: | tree | raw B | transfer B | |---|---|---| | main `2fee36ff` | 6,825,378 | 2,053,999 | | main `2fee36ff` + the move | 6,821,006 | 2,052,708 | | main `78e5eefa4d` (adds #14113) + the move | 6,821,334 | 2,052,857 | | + #14183 | 6,821,410 | 2,052,614 | | + #14172 (one tooltip design) | 6,825,307 | 2,053,990 | | this PR (main `b227654927`, adds #14184, + the move) | 6,825,725 | 2,054,072 | - **The move saves:** 4,372 B raw and 1,291 B transfer. - **#14113 adds:** 328 B raw and 149 B transfer on this build. - **Landed while main was over, with no raise:** #14183 (+76 B raw, -243 B transfer), #14172 (+3,897 B raw, +1,376 B transfer, the shared tooltip is in the eager shell) and #14184 (+418 B raw, +82 B transfer). This is the treadmill the absolute reset stops: while main is red on this check, growth lands unaccounted. - **With the new limits:** `within budget (0.2 KB transfer, 0.2 KB raw to spare)`. - **`npm run typecheck`:** clean. - **`bundle-budget-cli.test.ts`, `bundle-budget-closure.test.ts`, `image-prompt-enhance.test.ts` and `loaded-models-platform-matrix.test.ts`:** 74 passed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
Fixes #14035
Studio matched every shortcut on
KeyboardEvent.code, the QWERTY position of the key. On Dvorak and other remapped Latin layouts that meant:Changes
One helper,
eventCode, now decides which code a keydown answers to, used both for matching (matchesBinding) and for recording / search (bindingFromEvent):,on the W position) answers as that punctuation, so Mod+Comma stays reachable./on the QWERTY[position andzon the/one, so that is its only Ctrl+/). Recording keeps the position there, as before./only with Shift, so the position is the only way to reach Mod+Slash there), the keypad, layouts that type no Latin letter (Russian and so on, as browsers do), and Option chords on macOS, where Option rewrites the letter.US QWERTY routing is unchanged: a test walks every letter, digit and punctuation key, with and without Shift, on both platforms, and checks each still answers to its own position. Stored binding values keep their format, so existing overrides load as before. This mirrors what the plain-paste chord detection in
pasted-text.tsalready does.Test plan
node --experimental-strip-types --test tests/keyboard-shortcuts.test.ts: 97 pass. The new layout tests fail against main's matching code; the US QWERTY identity test passes on both.npm test: 12542 pass, 0 failnode scripts/typecheck.mjs --testsBefore / after
Studio in Chromium with each press sent exactly as a Dvorak keyboard sends it (
code= the QWERTY position,key= the Dvorak letter). Left is the merge base, right is this PR.Ctrl+X with "hello world" selected in the composer: the merge base collapses the sidebar and leaves the text; this PR leaves the sidebar alone and the text is cut.
Settings > Shortcuts > Toggle sidebar > Change shortcut, then Ctrl plus the key that types b: the merge base records Ctrl+N and flags it as clashing with New chat; this PR records Ctrl+B.
The same presses were also checked with real X11 key events under a Dvorak layout in Firefox 157 and Chromium: identical results, and US QWERTY unchanged on both sides.