Remove ITerminal dependency in SelectionManager

This commit is contained in:
Daniel Imms
2019-06-23 14:29:59 -07:00
parent 4ecd0d2053
commit 88308f058c
3 changed files with 14 additions and 24 deletions
+4 -17
View File
@@ -6,27 +6,20 @@
import { assert } from 'chai';
import { SelectionManager, SelectionMode } from './SelectionManager';
import { SelectionModel } from 'browser/selection/SelectionModel';
import { ITerminal } from './Types';
import { IBuffer } from 'common/buffer/Types';
import { IBufferLine } from 'common/Types';
import { MockTerminal } from './TestUtils.test';
import { MockBufferService, MockOptionsService, MockCoreService } from 'common/TestUtils.test';
import { BufferLine } from 'common/buffer/BufferLine';
import { IBufferService, IOptionsService } from 'common/services/Services';
import { MockCharSizeService, MockMouseService } from 'browser/TestUtils.test';
import { CellData } from 'common/buffer/CellData';
class TestMockTerminal extends MockTerminal {
emit(event: string, data: any): void {}
}
import { IBuffer } from 'common/buffer/Types';
class TestSelectionManager extends SelectionManager {
constructor(
terminal: ITerminal,
bufferService: IBufferService,
optionsService: IOptionsService
) {
super(terminal, null, new MockCharSizeService(10, 10), bufferService, new MockCoreService(), new MockMouseService(), optionsService);
super(() => {}, null, null, new MockCharSizeService(10, 10), bufferService, new MockCoreService(), new MockMouseService(), optionsService);
}
public get model(): SelectionModel { return this._model; }
@@ -44,22 +37,16 @@ class TestSelectionManager extends SelectionManager {
}
describe('SelectionManager', () => {
let terminal: ITerminal;
let buffer: IBuffer;
let bufferService: IBufferService;
let optionsService: IOptionsService;
let selectionManager: TestSelectionManager;
beforeEach(() => {
terminal = new TestMockTerminal();
optionsService = new MockOptionsService();
bufferService = new MockBufferService(20, 20, optionsService);
terminal.buffers = bufferService.buffers;
terminal.cols = 20;
terminal.rows = 20;
terminal.buffer = terminal.buffers.active;
buffer = terminal.buffer;
selectionManager = new TestSelectionManager(terminal, bufferService, optionsService);
buffer = bufferService.buffer;
selectionManager = new TestSelectionManager(bufferService, optionsService);
});
function stringToRow(text: string): IBufferLine {
+5 -6
View File
@@ -3,14 +3,12 @@
* @license MIT
*/
import { ITerminal } from './Types';
import { ISelectionManager, ISelectionRedrawRequestEvent } from 'browser/selection/Types';
import { IBuffer } from 'common/buffer/Types';
import { IBufferLine } from 'common/Types';
import { IBufferLine, IDisposable } from 'common/Types';
import * as Browser from 'common/Platform';
import { SelectionModel } from 'browser/selection/SelectionModel';
import { CellData } from 'common/buffer/CellData';
import { IDisposable } from 'xterm';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { ICharSizeService, IMouseService } from 'browser/services/Services';
import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services';
@@ -113,7 +111,8 @@ export class SelectionManager implements ISelectionManager {
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
constructor(
private readonly _terminal: ITerminal,
private readonly _scrollLines: (amount: number, suppressEvent: boolean) => void,
private readonly _element: HTMLElement,
private readonly _screenElement: HTMLElement,
private readonly _charSizeService: ICharSizeService,
private readonly _bufferService: IBufferService,
@@ -625,7 +624,7 @@ export class SelectionManager implements ISelectionManager {
*/
private _dragScroll(): void {
if (this._dragScrollAmount) {
this._terminal.scrollLines(this._dragScrollAmount, false);
this._scrollLines(this._dragScrollAmount, false);
// Re-evaluate selection
// If the cursor was above or below the viewport, make sure it's at the
// start or end of the viewport respectively. This should only happen when
@@ -659,7 +658,7 @@ export class SelectionManager implements ISelectionManager {
if (event.altKey) {
const coordinates = this._mouseService.getCoords(
event,
this._terminal.element,
this._element,
this._bufferService.cols,
this._bufferService.rows,
false
+5 -1
View File
@@ -641,7 +641,11 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.register(this.onFocus(() => this._renderService.onFocus()));
this.register(this._renderService.onDimensionsChange(() => this.viewport.syncScrollArea()));
this.selectionManager = new SelectionManager(this, this.screenElement, this._charSizeService, this._bufferService, this._coreService, this._mouseService, this.optionsService);
this.selectionManager = new SelectionManager(
(amount: number, suppressEvent: boolean) => this.scrollLines(amount, suppressEvent),
this.element, this.screenElement, this._charSizeService, this._bufferService, this._coreService,
this._mouseService, this.optionsService
);
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._renderService.onSelectionChanged(e.start, e.end, e.columnSelectMode)));