diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index f2f5cb9a..97d48eac 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -20,7 +20,7 @@ class TestSelectionManager extends SelectionManager { constructor( terminal: ITerminal ) { - super(terminal, new MockCharSizeService(10, 10)); + super(terminal, new MockCharSizeService(10, 10), new MockBufferService(20, 20)); } public get model(): SelectionModel { return this._model; } diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 498b4abe..9aa1f99f 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -13,6 +13,7 @@ import { CellData } from 'common/buffer/BufferLine'; import { IDisposable } from 'xterm'; import { EventEmitter2, IEvent } from 'common/EventEmitter2'; import { ICharSizeService } from 'browser/services/Services'; +import { IBufferService } from 'common/services/Services'; /** * The number of pixels the mouse needs to be above or below the viewport in @@ -117,12 +118,13 @@ export class SelectionManager implements ISelectionManager { constructor( private _terminal: ITerminal, - private _charSizeService: ICharSizeService + private _charSizeService: ICharSizeService, + bufferService: IBufferService ) { this._initListeners(); this.enable(); - this._model = new SelectionModel(_terminal); + this._model = new SelectionModel(_terminal, bufferService); this._activeSelectionMode = SelectionMode.NORMAL; } diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index 1b011e25..28420a78 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -8,12 +8,14 @@ import { ITerminal } from './Types'; import { SelectionModel } from './SelectionModel'; import { BufferSet } from './BufferSet'; import { MockTerminal, MockOptionsService, MockBufferService } from './TestUtils.test'; +import { IBufferService } from 'common/services/Services'; class TestSelectionModel extends SelectionModel { constructor( - terminal: ITerminal + terminal: ITerminal, + bufferService: IBufferService ) { - super(terminal); + super(terminal, bufferService); } } @@ -23,13 +25,14 @@ describe('SelectionManager', () => { beforeEach(() => { terminal = new MockTerminal(); + const bufferService = new MockBufferService(80, 2); terminal.buffers = new BufferSet( new MockOptionsService({ scrollback: 10 }), - new MockBufferService(80, 2) + bufferService ); terminal.buffer = terminal.buffers.active; - model = new TestSelectionModel(terminal); + model = new TestSelectionModel(terminal, bufferService); }); describe('clearSelection', () => { diff --git a/src/SelectionModel.ts b/src/SelectionModel.ts index f87667f2..44cd4cac 100644 --- a/src/SelectionModel.ts +++ b/src/SelectionModel.ts @@ -4,6 +4,7 @@ */ import { ITerminal } from './Types'; +import { IBufferService } from 'common/services/Services'; /** * Represents a selection within the buffer. This model only cares about column @@ -33,7 +34,8 @@ export class SelectionModel { public selectionEnd: [number, number]; constructor( - private _terminal: ITerminal + private _terminal: ITerminal, + private _bufferService: IBufferService ) { this.clearSelection(); } @@ -69,7 +71,7 @@ export class SelectionModel { */ public get finalSelectionEnd(): [number, number] { if (this.isSelectAllActive) { - return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1]; + return [this._bufferService.cols, this._terminal.buffer.ybase + this._bufferService.rows - 1]; } if (!this.selectionStart) { @@ -79,8 +81,8 @@ export class SelectionModel { // Use the selection start + length if the end doesn't exist or they're reversed if (!this.selectionEnd || this.areSelectionValuesReversed()) { const startPlusLength = this.selectionStart[0] + this.selectionStartLength; - if (startPlusLength > this._terminal.cols) { - return [startPlusLength % this._terminal.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._terminal.cols)]; + if (startPlusLength > this._bufferService.cols) { + return [startPlusLength % this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols)]; } return [startPlusLength, this.selectionStart[1]]; } diff --git a/src/Terminal.ts b/src/Terminal.ts index 38efd3b4..47672c38 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -643,7 +643,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.register(this.addDisposableListener('focus', () => this._renderCoordinator.onFocus())); this.register(this._renderCoordinator.onDimensionsChange(() => this.viewport.syncScrollArea())); - this.selectionManager = new SelectionManager(this, this._charSizeService); + this.selectionManager = new SelectionManager(this, this._charSizeService, this._bufferService); this.register(this.selectionManager.onSelectionChange(() => this._onSelectionChange.fire())); this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this.selectionManager.onMouseDown(e))); this.register(this.selectionManager.onRedrawRequest(e => this._renderCoordinator.onSelectionChanged(e.start, e.end, e.columnSelectMode)));