Files
Netcatty/components/terminal/runtime/optionYankLastArg.ts
T
陈大猫andCursor c4edefdbe4 feat(terminal): pass Esc+. through for readline yank-last-arg (#3047)
* feat(terminal): pass Esc+. through for readline yank-last-arg

Autocomplete was swallowing Escape, and macOS Option+. typed ≥ instead of Meta-., so the standard shell shortcut never reached bash/zsh.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(terminal): allow Shift when Esc+_ yanks the last argument

Underscore is Shift+Minus, so rejecting all shiftKey follow-ups dropped M-_ after autocomplete dismissed.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(terminal): keep Esc+_ armed across the Shift keydown

Typing underscore emits Shift before Minus. Clearing the Meta prefix on that modifier event dropped M-_ after autocomplete dismiss.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(terminal): do not treat Esc+. as typed input

Yank-last-arg rewrites the shell line. Walking the ESC+. bytes appended a literal period to the command buffer and left autocomplete's typed buffer marked reliable.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-18 13:59:56 +08:00

38 lines
1.1 KiB
TypeScript

export interface OptionYankLastArgKeyEvent {
key: string;
code?: string;
altKey: boolean;
ctrlKey: boolean;
metaKey: boolean;
shiftKey: boolean;
}
const isPeriodKey = (e: OptionYankLastArgKeyEvent): boolean => (
e.code === "Period" || e.key === "." || e.key === "≥"
);
const isUnderscoreKey = (e: OptionYankLastArgKeyEvent): boolean => (
e.key === "_" || (e.code === "Minus" && e.shiftKey)
);
/**
* macOS Option+. / Option+_ → readline yank-last-arg (issue #2364).
*
* Ghostty/iTerm2/kitty/VS Code do not implement this themselves — they pass
* Meta-. through to bash/zsh. On macOS, Option+. types "≥" unless Option is
* Meta, so map those two physical keys to ESC+. / ESC+_ without turning every
* Option chord into Meta (unlike `altAsMeta`).
*
* Gated to macOS: Linux/Windows Alt+. already sends the ESC prefix via xterm.
*/
export function optionYankLastArgSequence(
e: OptionYankLastArgKeyEvent,
isMac: boolean,
): string | null {
if (!isMac) return null;
if (!e.altKey || e.ctrlKey || e.metaKey) return null;
if (isPeriodKey(e) && !e.shiftKey) return "\x1b.";
if (isUnderscoreKey(e)) return "\x1b_";
return null;
}