Skip to content

Studio: match letter shortcuts by the letter the layout types - #14113

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
Souravrajvi0:feat/keyboard-layout-shortcut-labels-3a30
Oct 19, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
Souravrajvi0:feat/keyboard-layout-shortcut-labels-3a30

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Ctrl+X (the key on the QWERTY B position) toggled the sidebar instead of cutting text, and Ctrl+Z (the QWERTY Slash position) opened the shortcuts list instead of undoing.
  • Settings > Shortcuts labelled the sidebar chord Ctrl+B while the key that fired it typed x, and recording Ctrl+B saved and showed Ctrl+N.

Changes

One helper, eventCode, now decides which code a keydown answers to, used both for matching (matchesBinding) and for recording / search (bindingFromEvent):

  • A key that types a Latin letter answers as that letter, the same way the browser's own Ctrl+C / Ctrl+X follow the layout. Labels already name the letter, so they now match the key pressed, in every browser (no Keyboard Layout API needed; Firefox and Safari do not implement it).
  • A letter position that types punctuation (Dvorak's , on the W position) answers as that punctuation, so Mod+Comma stays reachable.
  • A punctuation position also matches the punctuation it types (Dvorak types / on the QWERTY [ position and z on the / one, so that is its only Ctrl+/). Recording keeps the position there, as before.
  • Everything else keeps its position: digits, other punctuation (German types / 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.ts already 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 fail
  • node scripts/typecheck.mjs --tests

Before / 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.

Dvorak Ctrl+X: merge base collapses the sidebar and keeps the selected text; this PR cuts the text

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.

Recording Ctrl+B on Dvorak: merge base saves Ctrl+N with a conflict warning; this PR saves 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.

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.
@danielhanchen danielhanchen self-assigned this Oct 18, 2026
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]
@danielhanchen danielhanchen changed the title fix(studio): keyboard shortcut labels for non-QWERTY layouts Studio: match letter shortcuts by the letter the layout types Oct 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-19T03:40:42.825895Z d0d61da New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +563 to +564
const typed = keyToCode(key);
if (typed !== key) return typed;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +594 to +595
eventCode(event, mac) !== binding.code &&
typedPunctuation(event, mac) !== binding.code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 18, 2026
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
@danielhanchen

Copy link
Copy Markdown
Member

Frontend build + bundle sanity is still just over the startup budget after the raise in this PR:

over the startup budget: transfer 1999.8 KB > 1999.7 KB

The new transferBytes in studio/frontend/scripts/check-bundle-budget.ts is about 0.1 KB short of what the build measures against the current base (2429c7a3). Re-measure with npm run build && npm run bundle:check on a fresh merge of main, and set the limit to the measured transfer plus the same small margin the earlier raises used.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 4b5aa8a96d

ℹ️ 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".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen
danielhanchen merged commit 78e5eef into unslothai:main Oct 19, 2026
danielhanchen added a commit that referenced this pull request Oct 19, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] keyboard shortcuts UI does not match key labels on alternative keyboard layouts

2 participants