Adopt in SelectionManager

This commit is contained in:
Daniel Imms
2019-06-08 15:26:53 -07:00
parent 53c3151de6
commit 0f2d560e01
3 changed files with 8 additions and 10 deletions
+4 -6
View File
@@ -4,13 +4,12 @@
*/ */
import { assert } from 'chai'; import { assert } from 'chai';
import { CharMeasure } from './CharMeasure';
import { SelectionManager, SelectionMode } from './SelectionManager'; import { SelectionManager, SelectionMode } from './SelectionManager';
import { SelectionModel } from './SelectionModel'; import { SelectionModel } from './SelectionModel';
import { BufferSet } from './BufferSet'; import { BufferSet } from './BufferSet';
import { ITerminal, IBuffer } from './Types'; import { ITerminal, IBuffer } from './Types';
import { IBufferLine } from 'core/Types'; import { IBufferLine } from 'core/Types';
import { MockTerminal } from './TestUtils.test'; import { MockTerminal, MockCharSizeService } from './TestUtils.test';
import { BufferLine, CellData } from 'core/buffer/BufferLine'; import { BufferLine, CellData } from 'core/buffer/BufferLine';
class TestMockTerminal extends MockTerminal { class TestMockTerminal extends MockTerminal {
@@ -19,10 +18,9 @@ class TestMockTerminal extends MockTerminal {
class TestSelectionManager extends SelectionManager { class TestSelectionManager extends SelectionManager {
constructor( constructor(
terminal: ITerminal, terminal: ITerminal
charMeasure: CharMeasure
) { ) {
super(terminal, charMeasure); super(terminal, new MockCharSizeService(10, 10));
} }
public get model(): SelectionModel { return this._model; } public get model(): SelectionModel { return this._model; }
@@ -52,7 +50,7 @@ describe('SelectionManager', () => {
terminal.buffers = new BufferSet(terminal); terminal.buffers = new BufferSet(terminal);
terminal.buffer = terminal.buffers.active; terminal.buffer = terminal.buffers.active;
buffer = terminal.buffer; buffer = terminal.buffer;
selectionManager = new TestSelectionManager(terminal, null); selectionManager = new TestSelectionManager(terminal);
}); });
function stringToRow(text: string): IBufferLine { function stringToRow(text: string): IBufferLine {
+3 -3
View File
@@ -7,12 +7,12 @@ import { ITerminal, ISelectionManager, IBuffer, ISelectionRedrawRequestEvent } f
import { IBufferLine } from 'core/Types'; import { IBufferLine } from 'core/Types';
import { MouseHelper } from './MouseHelper'; import { MouseHelper } from './MouseHelper';
import * as Browser from 'common/Platform'; import * as Browser from 'common/Platform';
import { CharMeasure } from './CharMeasure';
import { SelectionModel } from './SelectionModel'; import { SelectionModel } from './SelectionModel';
import { AltClickHandler } from './handlers/AltClickHandler'; import { AltClickHandler } from './handlers/AltClickHandler';
import { CellData } from 'core/buffer/BufferLine'; import { CellData } from 'core/buffer/BufferLine';
import { IDisposable } from 'xterm'; import { IDisposable } from 'xterm';
import { EventEmitter2, IEvent } from 'common/EventEmitter2'; import { EventEmitter2, IEvent } from 'common/EventEmitter2';
import { ICharSizeService } from 'ui/services/Services';
/** /**
* The number of pixels the mouse needs to be above or below the viewport in * The number of pixels the mouse needs to be above or below the viewport in
@@ -117,7 +117,7 @@ export class SelectionManager implements ISelectionManager {
constructor( constructor(
private _terminal: ITerminal, private _terminal: ITerminal,
private _charMeasure: CharMeasure private _charSizeService: ICharSizeService
) { ) {
this._initListeners(); this._initListeners();
this.enable(); this.enable();
@@ -375,7 +375,7 @@ export class SelectionManager implements ISelectionManager {
*/ */
private _getMouseEventScrollAmount(event: MouseEvent): number { private _getMouseEventScrollAmount(event: MouseEvent): number {
let offset = MouseHelper.getCoordsRelativeToElement(event, this._terminal.screenElement)[1]; let offset = MouseHelper.getCoordsRelativeToElement(event, this._terminal.screenElement)[1];
const terminalHeight = this._terminal.rows * Math.ceil(this._charMeasure.height * this._terminal.options.lineHeight); const terminalHeight = this._terminal.rows * Math.ceil(this._charSizeService.height * this._terminal.options.lineHeight);
if (offset >= 0 && offset <= terminalHeight) { if (offset >= 0 && offset <= terminalHeight) {
return 0; return 0;
} }
+1 -1
View File
@@ -646,7 +646,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.register(this.charMeasure.onCharSizeChanged(() => this._renderCoordinator.onCharSizeChanged())); this.register(this.charMeasure.onCharSizeChanged(() => this._renderCoordinator.onCharSizeChanged()));
this.register(this._renderCoordinator.onDimensionsChange(() => this.viewport.syncScrollArea())); this.register(this._renderCoordinator.onDimensionsChange(() => this.viewport.syncScrollArea()));
this.selectionManager = new SelectionManager(this, this.charMeasure); this.selectionManager = new SelectionManager(this, this._charSizeService);
this.register(this.selectionManager.onSelectionChange(() => this._onSelectionChange.fire())); this.register(this.selectionManager.onSelectionChange(() => this._onSelectionChange.fire()));
this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this.selectionManager.onMouseDown(e))); 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))); this.register(this.selectionManager.onRedrawRequest(e => this._renderCoordinator.onSelectionChanged(e.start, e.end, e.columnSelectMode)));