diff --git a/components/terminal/runtime/createXTermRuntime.test.ts b/components/terminal/runtime/createXTermRuntime.test.ts index c75ff122f..ddb4dfbcd 100644 --- a/components/terminal/runtime/createXTermRuntime.test.ts +++ b/components/terminal/runtime/createXTermRuntime.test.ts @@ -947,5 +947,6 @@ test("alternate-screen history preview stays selectable and copyable", async () assert.match(source, /shouldHideHistoryPreviewOnMouseDown/); assert.match(source, /shouldKeepHistoryPreviewOnKey/); assert.match(source, /previewSelection \|\| getTerminalSelectionForClipboard/); - assert.match(source, /term\.hasSelection\(\) \|\| Boolean\(previewSelection\)/); + assert.match(source, /hasCopyableSelection = term\.hasSelection\(\) \|\| Boolean\(previewSelection\)/); + assert.match(source, /shouldUseUrgentTerminalInterrupt\(e, \{ hasSelection: hasCopyableSelection \}\)/); }); diff --git a/components/terminal/runtime/createXTermRuntime.ts b/components/terminal/runtime/createXTermRuntime.ts index e4eb068ce..b81942b46 100644 --- a/components/terminal/runtime/createXTermRuntime.ts +++ b/components/terminal/runtime/createXTermRuntime.ts @@ -1458,6 +1458,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime } const previewSelection = getHistoryPreviewSelectionFromRoot(ctx.container); + const hasCopyableSelection = term.hasSelection() || Boolean(previewSelection); const forcedHistoryScrollPages = forcedHistoryScrollPagesForKey(e); if (forcedHistoryScrollPages !== null) { e.preventDefault(); @@ -1541,7 +1542,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime // the interrupt path hard-aborts instead (#2191). if ( e.key.length === 1 - && !shouldUseUrgentTerminalInterrupt(e, { hasSelection: term.hasSelection() }) + && !shouldUseUrgentTerminalInterrupt(e, { hasSelection: hasCopyableSelection }) ) { sudoAutofill.cancelHint(); // fall through: key becomes the first char of the manually typed password @@ -1574,7 +1575,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime : null; if ( (!kittySequenceForKeyDown || kittySequenceForKeyDown === "\x03") && - shouldUseUrgentTerminalInterrupt(e, { hasSelection: term.hasSelection() }) + shouldUseUrgentTerminalInterrupt(e, { hasSelection: hasCopyableSelection }) ) { const id = ctx.sessionRef.current; if (id && ctx.statusRef.current === "connected") { @@ -1704,7 +1705,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime const shouldForwardCopyToTerminal = shouldPassThroughCopyShortcut( action, - term.hasSelection() || Boolean(previewSelection), + hasCopyableSelection, e, ); if (shouldForwardCopyToTerminal && !kittySequenceForKeyDown) return true; @@ -1857,7 +1858,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime event: kittyEvent, fallbackToLegacy: true, urgentInterrupt: shouldUseUrgentTerminalInterrupt(e, { - hasSelection: term.hasSelection(), + hasSelection: hasCopyableSelection, }), }); if (forwarded) {