From e98a20f554d7c42e02b60bf5adf6a6b072423512 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 16 Aug 2025 04:42:54 +0000 Subject: [PATCH] Allow terminal sticky scroll only when rich shell integration (#261161) * Initial plan * Fix sticky scroll to require rich shell integration Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> * Remove redundant comment from terminal sticky scroll Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> * move richCommandDetection check to _tryEnable * last cleanup * rewrite _tryEnable() as suggested. * clear richDetectionListener * also clear when rich command detection is already there * cover no shell int, rich shell int, basic shell int * Don't leave a mess * Make conditional more explicit --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> Co-authored-by: Anthony Kim --- .../browser/terminalStickyScrollContribution.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollContribution.ts b/src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollContribution.ts index 9d2b55ea406..4537ef242d3 100644 --- a/src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollContribution.ts +++ b/src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollContribution.ts @@ -31,6 +31,7 @@ export class TerminalStickyScrollContribution extends Disposable implements ITer private readonly _enableListeners = this._register(new MutableDisposable()); private readonly _disableListeners = this._register(new MutableDisposable()); + private readonly _richCommandDetectionListeners = this._register(new MutableDisposable()); constructor( private readonly _ctx: ITerminalContributionContext, @@ -94,6 +95,7 @@ export class TerminalStickyScrollContribution extends Disposable implements ITer } private _tryEnable(): void { + const capability = this._ctx.instance.capabilities.get(TerminalCapability.CommandDetection); if (this._shouldBeEnabled()) { const xtermCtorEventually = TerminalInstance.getXtermConstructor(this._keybindingService, this._contextKeyService); this._overlay.value = this._instantiationService.createInstance( @@ -101,20 +103,30 @@ export class TerminalStickyScrollContribution extends Disposable implements ITer this._ctx.instance, this._xterm!, this._instantiationService.createInstance(TerminalInstanceColorProvider, this._ctx.instance.targetRef), - this._ctx.instance.capabilities.get(TerminalCapability.CommandDetection)!, + capability!, xtermCtorEventually ); + this._richCommandDetectionListeners.clear(); + } else if (capability && !capability.hasRichCommandDetection) { + this._richCommandDetectionListeners.value = capability.onSetRichCommandDetection(() => { + this._refreshState(); + }); + } else { + // No or Rich shell integration does not need listener + this._richCommandDetectionListeners.clear(); } } private _tryDisable(): void { if (!this._shouldBeEnabled()) { this._overlay.clear(); + this._richCommandDetectionListeners.clear(); } } private _shouldBeEnabled(): boolean { const capability = this._ctx.instance.capabilities.get(TerminalCapability.CommandDetection); - return !!(this._configurationService.getValue(TerminalStickyScrollSettingId.Enabled) && capability && this._xterm?.raw?.element); + const result = !!(this._configurationService.getValue(TerminalStickyScrollSettingId.Enabled) && capability && capability.hasRichCommandDetection && this._xterm?.raw?.element); + return result; } }