Skip to content

fix(terminal): translate Option/Alt + Forward-Delete to readline forward-kill-word (#21491) - #21893

Closed
bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:fix/21491-option-forward-delete-word
Closed

bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:fix/21491-option-forward-delete-word

Conversation

@bbingz

@bbingz bbingz commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

ELI5

Pressing Option + Delete (⌥⌦ / Alt + Delete) in an Orca terminal now deletes the word to the right, matching standard macOS terminal behavior and preventing stray characters or accidental line clearing in tools like Claude Code.

What Changed

  • Before: In terminal panes or Claude Code sessions, pressing Option + Forward-Delete (⌥⌦) sent raw escape sequence \x1b[3;3~ (CSI 3;3~). Shells without this binding would swallow the prefix and print a stray ~, while Claude Code would misinterpret the sequence and delete all text to the end of the line instead of a single word.
  • After: Option + Forward-Delete (⌥⌦ on macOS, Alt + Delete on Linux/Windows) translates to \x1bd (ESC d), which readline and CLI tools recognize as forward-kill-word. When the Kitty Keyboard Protocol is active, it defers to xterm so advanced TUIs receive native events.
  • Mechanism: In resolveTerminalShortcutAction (src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts), unified Alt+Backspace and non-numpad Alt+Delete to emit \x1bd for Delete and \x1b\x7f for Backspace.

Why

On macOS and in readline-based shells, Option + Backspace deletes the word to the left (backward-kill-word), and Option + Forward-Delete symmetrically deletes the word to the right (forward-kill-word). Unifying this alongside Alt+Backspace provides expected muscle-memory behavior across terminals (iTerm2, Terminal.app, Ghostty) while keeping cyclomatic complexity low and remaining strictly within line-count limits.

Alternatives considered:

  • Letting shells handle raw CSI 3;3~: Standard readline and Zsh ZLE configurations do not bind CSI 3;3~ by default, leading to terminal noise or application misbehavior.
  • Handling macOS only: Alt+Delete on Linux and Windows readline shells also expects forward-kill-word (\x1bd), so treating both platforms consistently aligns with the existing Alt+Backspace and Alt+Arrow policies.

Linked Issue

Fixes #21491

Visual Proof

N/A - Keyboard input sequence mapping inside terminal pane; verified with automated unit test suite.

Testing

  • Automated tests added:
    • Added dedicated test suite src/renderer/src/components/terminal-pane/terminal-shortcut-forward-delete.test.ts covering macOS, Linux/Windows, Kitty protocol negotiation, numpad exclusion, and modifier isolation.
  • Local verification:
    • node config/scripts/check-changed-code-quality.mjs (passed with 0 findings)
    • node config/scripts/check-max-lines-ratchet.mjs (passed with 0 new bypasses; file stays at 293 lines)
    • tsc --noEmit across CLI and Web configurations (all passed)
    • vitest run on terminal-shortcut-forward-delete.test.ts and terminal-shortcut-policy.test.ts (40 passed)

AI Disclosure

Developed with Google Antigravity.

Agent skill upstream boundary

  • Not applicable

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b1aca00f-b951-4ed3-bcbe-7abea67fbcc1

📥 Commits

Reviewing files that changed from the base of the PR and between 7a6d100 and 9b5d240.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-shortcut-forward-delete.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The terminal shortcut policy now maps non-keypad Alt+Delete to \x1bd, while Alt+Backspace remains mapped to \x1b\x7f. The resolver returns null when the Kitty keyboard protocol is active. New tests cover macOS, non-macOS, keypad Delete, plain Delete, Meta+Delete, and Ctrl+Alt+Delete behavior.

Priority: ➖ Normal

Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: translating Option/Alt + Forward-Delete into the readline forward-kill-word sequence.
Description check ✅ Passed The description covers the required change, rationale, linked issue, visual-proof exception, testing, AI disclosure, scope boundary, and checklist. The Review and Notes sections are not included, but …
Linked Issues check ✅ Passed The implementation addresses #21491. For Alt/Option + Delete, excluding numpad Delete, resolveTerminalShortcutAction sends \\x1bd, which maps to readline forward-kill-word and replaces the proble…
Out of Scope Changes check ✅ Passed The changes stay within #21491. The Backspace branch keeps its existing \\x1b\\x7f behavior, while the shared condition and comment support the new Delete mapping. The added tests verify the requested…
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Alt/Option + Forward-Delete → forward-kill-word: resolveTerminalShortcutAction now matches non-numpad Delete alongside Backspace in the Alt-modified branch, emitting \x1bd (ESC d) while keeping \x1b\x7f for Alt+Backspace. Kitty-negotiated panes still return null before emitting bytes, so xterm sends native escapes.
  • Numpad exclusion: event.code?.startsWith('Numpad') !== true keeps keypad Delete/NumpadDecimal out of the translation, preserving the kitty functional-numpad identity path in resolveTerminalOptionShortcutAction.
  • Tests: the new terminal-shortcut-forward-delete.test.ts pins macOS, non-mac, kitty deferral, numpad exclusion, and modifier isolation with exact sendInput byte assertions — they would fail against the pre-PR behavior.

I specifically checked the non-mac half against the local Windows ConPTY hazard the repo already guards for Ctrl+Arrow (Escape→PSReadLine RevertLine). Upstream microsoft/terminal and PSReadLine sources show ConPTY fuses ESC d into a single Alt+d key event, and PSReadLine's default Windows bindings map Alt+d to KillWord — so the unguarded translation here is correct and guarding it would instead send Alt+Delete, which PSReadLine does not bind. This also matches the existing unguarded Alt+Arrow / Alt+Backspace branches. The dashboard preview terminal routes through resolvePreviewShortcutAction, which delegates to this same policy, so there is no parity gap.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

nwparker added a commit that referenced this pull request Oct 25, 2026
…#33296)

macOS: Option+Forward-Delete sends ESC d (delete word forward) for shells and inline agent TUIs, so Claude Code deletes a word instead of the whole line; full-screen non-agent apps (vim, nano, less) keep the native CSI 3;3~. Linux/Windows unchanged. Fixes #21491. Supersedes #21893.

Co-authored-by: bbingz <11211020+bbingz@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @bbingz! Your commit landed via #33296 (kept, plus Co-authored-by): ESC d is sent on macOS only, and full-screen non-agent apps like vim keep the native sequence. Closing as superseded.

@nwparker nwparker closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Option + Forward-Delete deletes to end of line in Claude code, types ~ in terminal

2 participants