From b0839dbaad4faefdcc201f18d627eec46f8abd59 Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:37:40 +0800 Subject: [PATCH] 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 --- .../terminalAutocompleteKeyEvent.ts | 2 +- .../terminalAutocompleteKeyEvent.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/terminal/autocomplete/terminalAutocompleteKeyEvent.ts b/components/terminal/autocomplete/terminalAutocompleteKeyEvent.ts index 538961d00..fb37c56a8 100644 --- a/components/terminal/autocomplete/terminalAutocompleteKeyEvent.ts +++ b/components/terminal/autocomplete/terminalAutocompleteKeyEvent.ts @@ -88,7 +88,7 @@ export function handleTerminalAutocompleteKeyEvent( writeToTerminal(metaFollowUp); return false; } - if (e.key !== "Escape") { + if (e.key !== "Escape" && e.key !== "Shift" && e.key !== "Control" && e.key !== "Alt" && e.key !== "Meta") { escMetaPrefixUntilRef.current = 0; } diff --git a/components/terminal/terminalAutocompleteKeyEvent.test.ts b/components/terminal/terminalAutocompleteKeyEvent.test.ts index 55bc4c9bb..cb68c9521 100644 --- a/components/terminal/terminalAutocompleteKeyEvent.test.ts +++ b/components/terminal/terminalAutocompleteKeyEvent.test.ts @@ -266,6 +266,26 @@ test("Esc+_ after dismissing the popup sends ESC+_ to the shell", () => { assert.deepEqual(writes, ["\x1b_"]); }); +test("Esc then Shift keydown then _ still yanks (Shift is a separate event)", () => { + const { context, writes } = createContext(); + handleTerminalAutocompleteKeyEvent(keyEvent("Escape"), context); + context.stateRef.current = { + ...context.stateRef.current, + popupVisible: false, + suggestions: [], + }; + + const shiftDown = shiftKeyEvent("Shift"); + assert.equal(handleTerminalAutocompleteKeyEvent(shiftDown, context), true); + assert.ok(context.escMetaPrefixUntilRef.current > 1_000); + + const underscore = shiftKeyEvent("_"); + const result = handleTerminalAutocompleteKeyEvent(underscore, context); + + assert.equal(result, false); + assert.deepEqual(writes, ["\x1b_"]); +}); + test("Esc then a non-Meta follow-up does not inject ESC and lets the key through", () => { const { context, writes } = createContext(); handleTerminalAutocompleteKeyEvent(keyEvent("Escape"), context);