fix(desktop): translate macOS ⌥⌫ (Option+Backspace) to delete-previous-word in terminal

Draft
GI
4mo ago
+25-0

What this addresses

Issue #5604 is a tracker consolidating many stale terminal-input issues. Rather than a single bug, it lists ~25 sub-issues. This PR takes one concrete, reproducible, and cleanly fixable item from that list — #2222 (macOS-native text-editing shortcuts) — and closes the specific gap that still reproduces.

The bug

translateLineEditChord (apps/desktop/src/renderer/lib/terminal/line-edit-translations.ts) already implements most of the macOS shortcuts #2222 asks for:

ShortcutStatus before this PR
⌘← / ⌘→ (line start/end)✅ implemented
⌘⌫ (delete to start of line)✅ implemented
⌥← / ⌥→ (word movement)✅ implemented
⌥⌫ (delete previous word)❌ missing

The alt branch only handled ArrowLeft/ArrowRight, so Option+Backspace fell through the translator, got CSI-u encoded by xterm's kitty keyboard protocol, and did nothing useful in the shell — exactly the "Current Terminal Behavior: Nothing" row in #2222.

Root cause

translateLineEditChord's isMac && onlyMod(event, "alt") block mapped the two arrow keys but never Backspace, even though the sibling meta branch already handled Backspace (delete-to-start).

The fix

Add one mapping in the alt branch:

if (key === "Backspace") return "\x1b\x7f";

ESC + DEL (\x1b\x7f) is the readline/zsh backward-kill-word sequence. It respects word boundaries the same way native macOS text inputs do, and it's consistent across bash and zsh (unlike ⌘⌫'s \x15, whose meaning differs per shell).

Tests

line-edit-translations.test.ts:

  • Reproduction → new test asserting Mac Option+Backspace maps to \x1b\x7f. Before the fix it returned null (bug reproduced); after the fix it passes.
  • Guard → new test asserting Option+Backspace is not translated on non-Mac platforms.

All 9 tests in the file pass. (The 10 failing tests elsewhere in the terminal dir are pre-existing document is not defined DOM-environment issues in appearance.test.ts, unrelated to this change.)

Refs #5604
Closes #2222


Open in Stage

Summary by cubic

Adds macOS Option+Backspace (⌥⌫) support in the terminal so it deletes the previous word, translating to ESC+DEL and matching native behavior. Closes #2222; addresses the terminal-input tracker in #5604.

  • Bug Fixes
    • Map ⌥⌫ to ESC+DEL (\x1b\x7f) on macOS for backward-kill-word.
    • Add tests for macOS mapping and non-macOS pass-through.