diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 041481b5..d9d3b24e 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -29,6 +29,10 @@ export class MockBufferService implements IBufferService { optionsService: IOptionsService = new MockOptionsService() ) { this.buffers = new BufferSet(optionsService, this); + // Listen to buffer activation events and automatically fire scroll events + this.buffers.onBufferActivate(e => { + this._onScroll.fire(e.activeBuffer.ydisp); + }); } public scrollPages(pageCount: number): void { throw new Error('Method not implemented.'); @@ -48,10 +52,6 @@ export class MockBufferService implements IBufferService { public scrollLines(disp: number, suppressScrollEvent?: boolean): void { throw new Error('Method not implemented.'); } - public syncScrollPosition(): void { - // Fire scroll event with current buffer position - this._onScroll.fire(this.buffer.ydisp); - } public resize(cols: number, rows: number): void { this.cols = cols; this.rows = rows; diff --git a/src/common/buffer/BufferSet.test.ts b/src/common/buffer/BufferSet.test.ts index 449c40b8..b6136094 100644 --- a/src/common/buffer/BufferSet.test.ts +++ b/src/common/buffer/BufferSet.test.ts @@ -83,68 +83,4 @@ describe('BufferSet', () => { }); }); - describe('scroll position synchronization', () => { - it('should call syncScrollPosition when switching from alt back to normal buffer', () => { - bufferSet.activateNormalBuffer(); - - const originalYDisp = 50; - bufferSet.normal.ydisp = originalYDisp; - bufferSet.normal.ybase = 100; - const mockBufferService = (bufferSet as any)._bufferService as MockBufferService; - - let syncScrollPositionCalled = false; - const originalSyncScrollPosition = mockBufferService.syncScrollPosition.bind(mockBufferService); - mockBufferService.syncScrollPosition = () => { - syncScrollPositionCalled = true; - originalSyncScrollPosition(); - }; - - bufferSet.activateAltBuffer(); - assert.equal(bufferSet.normal.ydisp, originalYDisp, 'Normal buffer ydisp should be preserved'); - syncScrollPositionCalled = false; - bufferSet.activateNormalBuffer(); - - assert.equal(bufferSet.normal.ydisp, originalYDisp, 'Normal buffer ydisp should be restored'); - assert.equal(syncScrollPositionCalled, true, 'activateNormalBuffer should call syncScrollPosition'); - assert.equal(bufferSet.active, bufferSet.normal, 'Normal buffer should be active'); - }); - - it('should preserve normal buffer scroll position when switching back from alt buffer', () => { - bufferSet.activateNormalBuffer(); - const normalScrollPos = 80; - bufferSet.normal.ydisp = normalScrollPos; - bufferSet.normal.ybase = 150; - - bufferSet.activateAltBuffer(); - bufferSet.alt.ydisp = 0; - bufferSet.alt.ybase = 0; - bufferSet.activateNormalBuffer(); - - assert.equal(bufferSet.normal.ydisp, normalScrollPos, 'Normal buffer should maintain its scroll position'); - assert.equal(bufferSet.active, bufferSet.normal, 'Normal buffer should be active'); - assert.notEqual(bufferSet.normal.ydisp, bufferSet.alt.ydisp, 'Normal and alt buffer should have different scroll positions'); - }); - - it('should fire scroll event with correct position when syncScrollPosition is called', () => { - const mockBufferService = (bufferSet as any)._bufferService as MockBufferService; - - bufferSet.activateNormalBuffer(); - const testScrollPosition = 42; - - mockBufferService.buffer.ydisp = testScrollPosition; - assert.equal(mockBufferService.buffer.ydisp, testScrollPosition, 'Active buffer ydisp should be set correctly'); - - let scrollEventFired = false; - let scrollEventPosition = -1; - - mockBufferService.onScroll((position: number) => { - scrollEventFired = true; - scrollEventPosition = position; - }); - - mockBufferService.syncScrollPosition(); - assert.equal(scrollEventFired, true, 'syncScrollPosition should fire scroll event'); - assert.equal(scrollEventPosition, testScrollPosition, `Scroll event should contain current buffer ydisp`); - }); - }); }); diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index 54390f2a..8f3a6aec 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -91,8 +91,6 @@ 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 85699f6f..616e5619 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -37,6 +37,9 @@ export class BufferService extends Disposable implements IBufferService { this.cols = Math.max(optionsService.rawOptions.cols || 0, MINIMUM_COLS); this.rows = Math.max(optionsService.rawOptions.rows || 0, MINIMUM_ROWS); this.buffers = this._register(new BufferSet(optionsService, this)); + this._register(this.buffers.onBufferActivate(e => { + this._onScroll.fire(e.activeBuffer.ydisp); + })); } public resize(cols: number, rows: number): void { @@ -149,10 +152,4 @@ export class BufferService extends Disposable implements IBufferService { } } - /** - * 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 58ee113f..9c3aebf7 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -22,7 +22,6 @@ 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; }