diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 127e1f24..ccdb54ae 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -46,6 +46,9 @@ export class MockBufferService implements IBufferService { public scrollLines(disp: number, suppressScrollEvent?: boolean): void { throw new Error('Method not implemented.'); } + public syncScrollPosition(): void { + // Mock implementation - no-op for tests + } public resize(cols: number, rows: number): void { this.cols = cols; this.rows = rows; diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index 8f3a6aec..54390f2a 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -91,6 +91,8 @@ export class BufferSet extends Disposable implements IBufferSet { activeBuffer: this._normal, inactiveBuffer: this._alt }); + // Prevent scrollbar "teleport" to top of the terminal, from previous alt buffer. + this._bufferService.syncScrollPosition(); } /** diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index c4698e68..85699f6f 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -148,4 +148,11 @@ export class BufferService extends Disposable implements IBufferService { this._onScroll.fire(buffer.ydisp); } } + + /** + * Synchronize the scroll position by firing a scroll event with the current buffer's ydisp. + */ + public syncScrollPosition(): void { + this._onScroll.fire(this.buffer.ydisp); + } } diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 9c3aebf7..58ee113f 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -22,6 +22,7 @@ export interface IBufferService { onScroll: Event; scroll(eraseAttr: IAttributeData, isWrapped?: boolean): void; scrollLines(disp: number, suppressScrollEvent?: boolean): void; + syncScrollPosition(): void; resize(cols: number, rows: number): void; reset(): void; }