Skip to content

fix: support option/alt+arrow word navigation in terminal - #699

Merged
Jinwoo-H merged 1 commit into
stablyai:mainfrom
dylanklohr:fix/terminal-word-navigation-shortcuts
Apr 16, 2026
Merged

Jinwoo-H merged 1 commit into
stablyai:mainfrom
dylanklohr:fix/terminal-word-navigation-shortcuts

Conversation

@dylanklohr

Copy link
Copy Markdown
Contributor

Summary

option+←/→ on macOS (alt+←/→ on Linux/Windows) now navigates word-by-word in Orca's integrated terminal, matching iTerm2 / Ghostty / Terminal.app behavior with default shell configs. Before this fix, the keys emitted the xterm CSI sequences \e[1;3D / \e[1;3C, which readline doesn't bind — the cursor wouldn't move, and depending on the shell the escape bytes could appear at the prompt as literal garbage.

Fixes #696.

Root cause

  • Orca's terminal sets macOptionIsMeta: true, which is why option+b / option+f already work (xterm.js emits \eb / \ef, readline's default bindings).
  • For the arrow keys, however, xterm.js emits CSI modifier sequences (\e[1;3D / \e[1;3C) that default readline doesn't recognize as word-nav.
  • Fix: intercept alt+ArrowLeft/Right in terminal-shortcut-policy.ts (the pure allowlist introduced by fix: audit terminal shortcut interception #519) and translate to \eb / \ef before xterm.js sees the event. Same pattern iTerm2's "Esc+" option-key mode uses.

Scope

One new if block in terminal-shortcut-policy.ts; one new it(...) block in its sibling test file covering macOS + Linux/Windows + three passthrough regression cases (alt+shift+arrow, alt+ctrl+arrow, plain arrow). No refactors.

Platform testing

  • macOS (darwin 25.2.0, Apple Silicon): verified locally with pnpm dev — cat shows ^[b / ^[f on option+←/→; at a shell prompt, cursor jumps word-by-word. Regression checks pass: option+b, option+f, option+Backspace still work; Cmd+F still opens terminal search.
  • Linux / Windows: not tested on hardware. The policy is platform-agnostic (same altKey semantics on all three OSes), and the unit test pins the non-Mac branch, so there's no reasonable path for this to regress on those platforms without also regressing on macOS.

Before / after

Test plan

  • pnpm lint — clean
  • pnpm typecheck — clean
  • pnpm test — 1716 tests pass
  • pnpm build — clean
  • Manual verification: cat with option+←/→ before/after the fix on macOS

AI code-review summary

  • Cross-platform keyboard behavior: the new branch gates on !metaKey && !ctrlKey && altKey && !shiftKey and key === 'ArrowLeft' | 'ArrowRight' — the same shape as the existing Alt+Backspace branch directly above. On macOS this matches option only; on Linux/Windows it matches alt only. Other chords (alt+shift, alt+ctrl, cmd+alt) fall through to xterm.js unchanged, and unit tests pin that.
  • Security: the branch only emits two fixed, hard-coded 2-byte escape sequences (\x1bb, \x1bf) — no user input is interpolated, no path traversal or injection surface. sendInput is the same IPC path already used by Alt+Backspace, Cmd+Backspace, Cmd+Delete, and Shift+Enter.
  • Shortcut-allowlist correctness: the branch lives inside the centralized terminal-shortcut policy (the audit surface introduced by fix: audit terminal shortcut interception #519), so any future drift is visible via the pinned unit-test matrix.
  • Regression surface: passthrough guards (alt+shift+arrow, alt+ctrl+arrow, plain arrow) are explicitly tested so a later edit to this file can't silently start swallowing select-word chords or plain cursor moves.

Related: #519 (terminal-shortcut audit), #443 (Ctrl+R), #586 (Ctrl+D / EOF split fix).


X/Twitter: @dylanklohr

xterm.js emits \e[1;3D / \e[1;3C for option/alt+arrow, which default
readline (bash, zsh) does not bind — so word-by-word navigation silently
doesn't work. Translate to \eb / \ef inside the terminal shortcut policy
so option+←/→ on macOS and alt+←/→ on Linux/Windows match iTerm2's
"Esc+" option-key mode. Extends the stablyai#519 allowlist; no scope beyond
that.

Fixes stablyai#696

@Jinwoo-H Jinwoo-H 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.

Thank you for contributing, lgtm!

@Jinwoo-H
Jinwoo-H merged commit 9ff4951 into stablyai:main Apr 16, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

No support for word-navigation shortcuts (option/alt + ←/→, option/alt + b/f)

2 participants