Add _selectLineAt test
This commit is contained in:
@@ -7,6 +7,7 @@ import { ITerminal } from './Interfaces';
|
|||||||
import { CharMeasure } from './utils/CharMeasure';
|
import { CharMeasure } from './utils/CharMeasure';
|
||||||
import { CircularList } from './utils/CircularList';
|
import { CircularList } from './utils/CircularList';
|
||||||
import { SelectionManager } from './SelectionManager';
|
import { SelectionManager } from './SelectionManager';
|
||||||
|
import { SelectionModel } from "./SelectionModel";
|
||||||
|
|
||||||
class TestSelectionManager extends SelectionManager {
|
class TestSelectionManager extends SelectionManager {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -18,6 +19,9 @@ class TestSelectionManager extends SelectionManager {
|
|||||||
super(terminal, buffer, rowContainer, charMeasure);
|
super(terminal, buffer, rowContainer, charMeasure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get model(): SelectionModel { return this._model; }
|
||||||
|
|
||||||
|
public selectLineAt(line: number): void { this._selectLineAt(line); }
|
||||||
public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords); }
|
public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords); }
|
||||||
|
|
||||||
// Disable DOM interaction
|
// Disable DOM interaction
|
||||||
@@ -30,6 +34,7 @@ describe('SelectionManager', () => {
|
|||||||
let window: Window;
|
let window: Window;
|
||||||
let document: Document;
|
let document: Document;
|
||||||
|
|
||||||
|
let terminal: ITerminal;
|
||||||
let buffer: CircularList<any>;
|
let buffer: CircularList<any>;
|
||||||
let rowContainer: HTMLElement;
|
let rowContainer: HTMLElement;
|
||||||
let selectionManager: TestSelectionManager;
|
let selectionManager: TestSelectionManager;
|
||||||
@@ -39,7 +44,8 @@ describe('SelectionManager', () => {
|
|||||||
window = w;
|
window = w;
|
||||||
document = window.document;
|
document = window.document;
|
||||||
buffer = new CircularList<any>(100);
|
buffer = new CircularList<any>(100);
|
||||||
selectionManager = new TestSelectionManager(null, buffer, rowContainer, null);
|
terminal = <any>{ cols: 80 };
|
||||||
|
selectionManager = new TestSelectionManager(terminal, buffer, rowContainer, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -137,4 +143,14 @@ describe('SelectionManager', () => {
|
|||||||
assert.equal(selectionManager.selectionText, 'foo');
|
assert.equal(selectionManager.selectionText, 'foo');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('_selectLineAt', () => {
|
||||||
|
it('should select the entire line', () => {
|
||||||
|
buffer.push(stringToRow('foo bar'));
|
||||||
|
selectionManager.selectLineAt(0);
|
||||||
|
assert.equal(selectionManager.selectionText, 'foo bar', 'The selected text is correct');
|
||||||
|
assert.deepEqual(selectionManager.model.finalSelectionStart, [0, 0]);
|
||||||
|
assert.deepEqual(selectionManager.model.finalSelectionEnd, [terminal.cols, 0], 'The actual selection spans the entire column');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const LINE_DATA_CHAR_INDEX = 1;
|
|||||||
const LINE_DATA_WIDTH_INDEX = 2;
|
const LINE_DATA_WIDTH_INDEX = 2;
|
||||||
|
|
||||||
export class SelectionManager extends EventEmitter {
|
export class SelectionManager extends EventEmitter {
|
||||||
private _model: SelectionModel;
|
protected _model: SelectionModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The amount to scroll every drag scroll update (depends on how far the mouse
|
* The amount to scroll every drag scroll update (depends on how far the mouse
|
||||||
@@ -462,7 +462,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
this._model.selectionStartLength = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
|
this._model.selectionStartLength = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _selectLineAt(line: number): void {
|
protected _selectLineAt(line: number): void {
|
||||||
this._model.selectionStart = [0, line];
|
this._model.selectionStart = [0, line];
|
||||||
this._model.selectionStartLength = this._terminal.cols;
|
this._model.selectionStartLength = this._terminal.cols;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user