BufferService listen to onBufferActivate, remove tests

This commit is contained in:
Anthony Kim
2025-08-28 08:46:27 -07:00
parent 675b2c3a70
commit 753ea81fc0
5 changed files with 7 additions and 77 deletions
+4 -4
View File
@@ -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;
-64
View File
@@ -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`);
});
});
});
-2
View File
@@ -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();
}
/**
+3 -6
View File
@@ -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);
}
}
-1
View File
@@ -22,7 +22,6 @@ export interface IBufferService {
onScroll: Event<number>;
scroll(eraseAttr: IAttributeData, isWrapped?: boolean): void;
scrollLines(disp: number, suppressScrollEvent?: boolean): void;
syncScrollPosition(): void;
resize(cols: number, rows: number): void;
reset(): void;
}