[Bug] macOS: default Previous/Next message keybinds (⌘⌥[ / ⌘⌥]) never fire
What happened
On macOS the default keybinds for Previous message (mod+alt+[, ⌘⌥[) and Next message (mod+alt+], ⌘⌥]) never fire. The shortcut is listed in Settings → Shortcuts, the command is enabled, but pressing it does nothing. Re-binding the same commands to a letter combination (for example mod+alt+p) works, so the commands themselves are fine.
Environment
- macOS 26.6 (build 25G72, arm64)
- OpenCode Desktop 2.0.26
Steps to reproduce
- Open OpenCode Desktop on macOS.
- Press
Cmd+,→ Shortcuts. Confirm Previous message is bound to⌘⌥[and Next message to⌘⌥]. - Open a session with at least two turns and press
⌘⌥[(or run the command from the command palette).
Expected: the transcript navigates to the previous user message. Actual: nothing happens.
Root cause
keyFromKeyboardEvent in packages/app/src/shell/commands/command.tsx normalises event.key and only falls back to the physical key (event.code) when the code starts with Key:
export function keyFromKeyboardEvent(event: KeyboardEvent) {
const key = normalizeKey(event.key)
if (!event.altKey || /^[a-z0-9]$/.test(key)) return key
if (!event.code.startsWith("Key") || event.code.length !== 4) return key
return event.code.slice(3).toLowerCase()
}
macOS composes a different character when Option is held, and the fallback only covers KeyA–KeyZ:
| Pressed | event.key |
event.code |
Recovered | Matches binding? |
|---|---|---|---|---|
⌥[ |
“ |
BracketLeft |
“ |
❌ (mod+alt+[ expects [) |
⌥] |
‘ |
BracketRight |
‘ |
❌ |
⌥P |
π |
KeyP |
p |
✅ |
⌥L |
¬ |
KeyL |
l |
✅ |
The physical-key fallback exists precisely because of this composition (see the existing meta+alt+l / ¬ case in command.test.ts), but it stops at letters. mod+alt+[ and mod+alt+] are the only default bindings that pair Option with punctuation, so both are dead out of the box on macOS — every macOS desktop/web user hits this.
Verified locally: pressing ⌥[ in any text field on macOS produces “, and ⌥] produces ‘.
Suggested fix
Recover the physical key for punctuation codes too, using the same key names that appear in keybind strings:
const ALT_PUNCTUATION: Record<string, string> = {
BracketLeft: "[",
BracketRight: "]",
// ...
}
const punctuation = ALT_PUNCTUATION[event.code]
if (punctuation !== undefined) return normalizeKey(punctuation)
Happy to open a PR for this.
Thanks for the detailed report and root-cause analysis! I confirmed this in the keybind-matching code. I couldn't run the macOS desktop app here, so I passed the keydown events macOS produces straight to matchKeybind / keyFromKeyboardEvent:
- Cmd+Option+
[(key: "“",code: "BracketLeft") does not matchmod+alt+[. - Cmd+Option+
](key: "‘",code: "BracketRight") does not matchmod+alt+]. - Cmd+Option+P (
key: "π",code: "KeyP") maps back topand matches.
The composed character is returned unchanged because the physical-key fallback only covers KeyA–KeyZ. This happens on 2.0.26 and still happens on the latest dev (38454c6). The script below reproduces it.
Until it's fixed, rebinding Previous/Next message to a letter combination in Settings → Shortcuts works around it. Your PR #54573 targets this fix.
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Reproduces #54571: macOS Option+[ / Option+] keydowns (composed to “ / ‘) never match
# the default mod+alt+[ / mod+alt+] keybinds. "mod" is Cmd on macOS, so meta+alt is used here
# (happy-dom never reports a Mac platform). Usage: REPO=/path/to/opencode [REF=v2.0.26] ./repro.sh
set -euo pipefail
REPO=${REPO:-/workspace/repo}
DIR="$REPO/packages/app/src/shell/commands"
if [ -n "${REF:-}" ]; then git -C "$REPO" show "$REF:packages/app/src/shell/commands/command.tsx" > "$DIR/command.tsx"; fi
cat > "$DIR/repro-54571.test.ts" <<'TS'
import { expect, test } from "bun:test"
import { keyFromKeyboardEvent, matchKeybind, parseKeybind } from "./command"
// Real macOS keydown events (US layout) with Cmd+Option held.
const rows = [
{ config: "meta+alt+[", event: { key: "“", code: "BracketLeft", metaKey: true, altKey: true } },
{ config: "meta+alt+]", event: { key: "‘", code: "BracketRight", metaKey: true, altKey: true } },
{ config: "meta+alt+p", event: { key: "π", code: "KeyP", metaKey: true, altKey: true } }, // control: works
]
for (const row of rows) {
test(`${row.config} matches macOS keydown key=${row.event.key} code=${row.event.code}`, () => {
const ev = new KeyboardEvent("keydown", row.event)
console.log(row.config, "-> keyFromKeyboardEvent =", JSON.stringify(keyFromKeyboardEvent(ev)))
expect(matchKeybind(parseKeybind(row.config), ev)).toBe(true)
})
}
TS
cd "$REPO/packages/app"
status=0; bun test src/shell/commands/repro-54571.test.ts || status=$?
rm -f "$DIR/repro-54571.test.ts"
[ -n "${REF:-}" ] && git -C "$REPO" checkout -q -- "$DIR/command.tsx"
exit $status
Run it: bash repro.sh
This should be fixed by #57301. It makes shortcut matching fall back to the physical bracket key when macOS Option produces a different character, so ⌘⌥[ and ⌘⌥] now match Previous/Next message. If they still don't fire on the latest version, comment here and we'll reopen.