Skip to content

Commit c4e35f0

Browse files
authored
Merge pull request microsoft#208433 from microsoft/tyriar/207959
Simplify terminal sticky scroll refresh by deferring to microtask
2 parents 712a3ee + 789b909 commit c4e35f0

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

src/vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollOverlay.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class TerminalStickyScrollOverlay extends Disposable {
5959
private _refreshListeners = this._register(new MutableDisposable());
6060

6161
private _state: OverlayState = OverlayState.Off;
62+
private _isRefreshQueued = false;
6263
private _rawMaxLineCount: number = 5;
6364

6465
constructor(
@@ -114,7 +115,7 @@ export class TerminalStickyScrollOverlay extends Disposable {
114115
}));
115116
this._register(this._xterm.raw.onResize(() => {
116117
this._syncOptions();
117-
this._throttledRefresh();
118+
this._refresh();
118119
}));
119120

120121
this._getSerializeAddonConstructor().then(SerializeAddon => {
@@ -175,37 +176,15 @@ export class TerminalStickyScrollOverlay extends Disposable {
175176
this._element?.classList.toggle(CssClasses.Visible, isVisible);
176177
}
177178

178-
/**
179-
* The entry point to refresh sticky scroll. This is synchronous and will call into the method
180-
* that actually refreshes using either debouncing or throttling depending on the situation.
181-
*
182-
* The goal is that if the command has changed to update immediately (with throttling) and if
183-
* the command is the same then update with debouncing as it's less likely updates will show up.
184-
* This approach also helps with:
185-
*
186-
* - Cursor move only updates such as moving horizontally in pagers which without this may show
187-
* the sticky scroll before hiding it again almost immediately due to everything not being
188-
* parsed yet.
189-
* - Improving performance due to deferring less important updates via debouncing.
190-
* - Less flickering when scrolling, while still updating immediately when the command changes.
191-
*/
192179
private _refresh(): void {
193-
if (!this._xterm.raw.element?.parentElement || !this._stickyScrollOverlay || !this._serializeAddon) {
180+
if (this._isRefreshQueued) {
194181
return;
195182
}
196-
const command = this._commandDetection.getCommandForLine(this._xterm.raw.buffer.active.viewportY);
197-
if (command && this._currentStickyCommand !== command) {
198-
this._throttledRefresh();
199-
} else {
200-
// If it's the same command, do not throttle as the sticky scroll overlay height may
201-
// need to be adjusted. This would cause a flicker if throttled.
183+
this._isRefreshQueued = true;
184+
queueMicrotask(() => {
202185
this._refreshNow();
203-
}
204-
}
205-
206-
@throttle(0)
207-
private _throttledRefresh(): void {
208-
this._refreshNow();
186+
this._isRefreshQueued = false;
187+
});
209188
}
210189

211190
private _refreshNow(): void {

0 commit comments

Comments
 (0)