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>
This commit is contained in:
bincxzandCursor committed 2026-08-18 13:37:40 +08:00
1 parent f960f4c78e
commit b0839dbaad
2 files changed
+21 -1

No files matched your search

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