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);