Clear selection manager when the terminal switches its buffer set or buffer.

This commit is contained in:
Andres Mejia
2018-01-18 17:48:29 -05:00
parent 90c8c85c09
commit a9b7ef5dc3
4 changed files with 24 additions and 7 deletions
+1 -1
View File
@@ -169,7 +169,7 @@ export interface IBuffer {
prevStop(x?: number): number;
}
export interface IBufferSet {
export interface IBufferSet extends IEventEmitter {
alt: IBuffer;
normal: IBuffer;
active: IBuffer;
+21 -5
View File
@@ -119,11 +119,27 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
this._mouseUpListener = event => this._onMouseUp(<MouseEvent>event);
// Only adjust the selection on trim, shiftElements is rarely used (only in
// reverseIndex) and delete in a splice is only ever used when the same
// number of elements was just added. Given this is could actually be
// beneficial to leave the selection as is for these cases.
this._buffer.lines.on('trim', (amount: number) => this._onTrim(amount));
this._updateBufferSetHandlers();
this._terminal.on('setup', () => {
this._onSetupHandler();
});
}
private _onSetupHandler(): void {
this.clearSelection();
this._updateBufferSetHandlers();
}
private _updateBufferSetHandlers(): void {
this._terminal.buffers.on('activate', (buffer: IBuffer) => {
this.clearSelection();
});
// Only adjust the selection on trim, shiftElements is rarely used (only in
// reverseIndex) and delete in a splice is only ever used when the same
// number of elements was just added. Given this is could actually be
// beneficial to leave the selection as is for these cases.
this._terminal.buffers.normal.lines.on('trim', (amount: number) => this._onTrim(amount));
this._terminal.buffers.alt.lines.on('trim', (amount: number) => this._onTrim(amount));
}
/**
+1
View File
@@ -292,6 +292,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
// Create the terminal's buffers and set the current buffer
this.buffers = new BufferSet(this);
this.emit('setup');
}
/**
+1 -1
View File
@@ -37,7 +37,7 @@ export class MockTerminal implements ITerminal {
throw new Error('Method not implemented.');
}
on(event: string, callback: () => void): void {
throw new Error('Method not implemented.');
/* Simply do nothing */
}
off(type: string, listener: IListenerType): void {
throw new Error('Method not implemented.');