Forward Opt+Enter as ESC+CR to alt-screen programs on macOS#9350
Forward Opt+Enter as ESC+CR to alt-screen programs on macOS#9350altjx wants to merge 1 commit intowarpdotdev:masterfrom
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: =.
|
When a TUI like Claude, vim, or fish runs in alt-screen mode, pressing Option+Enter on macOS without "Option as Meta" enabled was sending a bare `\r` to the PTY instead of the xterm-style `\x1b\r`. The legacy escape sequence path early-returned on Mac whenever `keystroke.meta` was unset, which is correct for letter keys (Opt+E = é) but wrong for Enter, which never has an Option-modified glyph. Allow alt-enter through the meta path and add `"enter" => "\r"` to the special-key map so the existing meta path also handles users who have Option-as-Meta enabled.
a2b37b0 to
6fe5041
Compare
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @altjx on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment |
|
@cla-bot check |
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @altjx on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
Summary
When a TUI like Claude, vim, or fish runs in alt-screen mode, pressing Option+Enter on macOS (without the "Option as Meta" setting enabled) was sending a bare
\rto the PTY instead of the xterm-style\x1b\r. The TUI then treated it as a plain Enter and submitted, instead of inserting a newline.Root cause
When alt-screen is active, focus is on
TerminalView(viafocus_terminal()→ctx.focus_self()), so the editor'salt-enterkeybinding never fires. The keystroke reachesalt_screen_element.rs'sKeyDownhandler and callsKeystrokeWithDetails::to_escape_sequence(). In the legacy fallback chain insidemeta_keystroke_to_escape_sequence(crates/warp_terminal/src/model/escape_sequences.rs):For default Mac config, Opt+Enter has
keystroke.alt = true, keystroke.meta = false. The function returnsNone, the rest of the chain returnsNonetoo, and thealt_screen_elementfalls through tokey_down(chars)which dispatches the raw\rto the PTY. The Macmeta-only gate is correct for letter keys (Option+E = é, etc., shouldn't becomeESC+e) but Enter has no Option-modified glyph, so it's safe — and expected by xterm-style TUIs — to encode Opt+Enter as a meta keystroke.A secondary bug: when users do have Option-as-Meta enabled (alt → meta upstream),
map_special_key_to_byteshad no entry for"enter", so the fallback at the end ofmeta_keystroke_to_escape_sequencesent literalESC+ the bytes of the string"enter".Changes
crates/warp_terminal/src/model/escape_sequences.rsalt-enterthroughmeta_keystroke_to_escape_sequenceon Mac even whenmetais unset."enter" => "\r"tomap_special_key_to_bytes.crates/warp_terminal/src/model/escape_sequences_test.rsalt-enterproducesESC+CRwhen Option-as-Meta is off.Test plan
cargo test -p warp_terminal escape_sequencespasses./script/macos/bundle --selfsign --nouniversal) and verified Opt+Enter inserts a newline in Claude inside the alt-screen instead of submittingextra_meta_keys.left_alt = true(Option-as-Meta enabled)ESC+letterNotes
Filed as a draft. Per CONTRIBUTING.md, bug fixes need a triaged issue first — happy to file one and link it back here once a maintainer confirms scope.