Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/warp_terminal/src/model/escape_sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ fn cursor_movement_keystroke_to_escape_sequence(
fn map_special_key_to_bytes(key: &str) -> Option<&[u8]> {
match key {
"backspace" => Some("\x7f".as_bytes()),
"enter" => Some("\r".as_bytes()),
"insert" => Some("\x1b[2~".as_bytes()),
"delete" => Some("\x1b[3~".as_bytes()),
"pageup" => Some("\x1b[5~".as_bytes()),
Expand All @@ -567,9 +568,13 @@ fn meta_keystroke_to_escape_sequence(
_mode_provider: &impl ModeProvider,
) -> Option<Vec<u8>> {
// On mac, we have a setting that allows users to map the Option keys to
// meta.
// meta. When that setting is off, Option+letter produces special glyphs
// (Option+E = é, etc.), so we don't treat alt as meta by default. The
// exception is Enter, which never has an Option-modified glyph — TUIs like
// claude/vim/fish expect Option+Enter to arrive as ESC+CR (xterm
// convention), so we let alt-enter through here too.
if OperatingSystem::get().is_mac() {
if !keystroke.meta {
if !keystroke.meta && !(keystroke.alt && keystroke.key == "enter") {
return None;
}
} else {
Expand Down
22 changes: 22 additions & 0 deletions crates/warp_terminal/src/model/escape_sequences_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,34 @@ fn test_meta_keystroke_to_escape_sequence() {
Keystroke::parse(metaify("'")).unwrap(),
vec![C0::ESC, b'\''],
),
(
Keystroke::parse(metaify("enter")).unwrap(),
vec![C0::ESC, b'\r'],
),
];

let terminal_model_mock = TerminalModelMock::new();
validate_keystroke_test_cases(test_cases, &terminal_model_mock);
}

/// On macOS, Option+Enter must encode as ESC+CR even when the user has not
/// enabled Option-as-Meta. Without this, the bare `\r` falls through to the
/// PTY and TUIs like claude/vim/fish treat it as plain Enter (submit) rather
/// than the Alt+Enter sequence they expect for inserting a newline.
#[test]
fn test_alt_enter_on_mac_yields_esc_cr_without_option_as_meta() {
if !OperatingSystem::get().is_mac() {
return;
}
let test_cases: &[(Keystroke, Vec<u8>)] = &[(
Keystroke::parse("alt-enter").unwrap(),
vec![C0::ESC, b'\r'],
)];

let terminal_model_mock = TerminalModelMock::new();
validate_keystroke_test_cases(test_cases, &terminal_model_mock);
}

#[test]
fn test_unmatched_keystroke_does_not_yield_escape_sequence() {
let test_cases: &[Keystroke] = &[
Expand Down