Merge remote-tracking branch 'origin/master' into pr/princjef/1460
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import jsdom = require('jsdom');
|
||||
import { ICharMeasure } from '../Types';
|
||||
import { assert } from 'chai';
|
||||
import { CharMeasure } from './CharMeasure';
|
||||
|
||||
describe('CharMeasure', () => {
|
||||
let dom: jsdom.JSDOM;
|
||||
let window: Window;
|
||||
let document: Document;
|
||||
let container: HTMLElement;
|
||||
let charMeasure: ICharMeasure;
|
||||
|
||||
beforeEach(() => {
|
||||
dom = new jsdom.JSDOM('');
|
||||
window = dom.window;
|
||||
document = window.document;
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
charMeasure = new CharMeasure(document, container);
|
||||
});
|
||||
|
||||
describe('measure', () => {
|
||||
it('should have _measureElement', () => {
|
||||
assert.isDefined((<any>charMeasure)._measureElement, 'new CharMeasure() should have created _measureElement');
|
||||
});
|
||||
|
||||
it('should be performed sync', () => {
|
||||
// Mock getBoundingClientRect since jsdom doesn't have a layout engine
|
||||
(<any>charMeasure)._measureElement.getBoundingClientRect = () => {
|
||||
return { width: 1, height: 1 };
|
||||
};
|
||||
charMeasure.measure({});
|
||||
assert.equal(charMeasure.height, 1);
|
||||
assert.equal(charMeasure.width, 1);
|
||||
});
|
||||
|
||||
it('should NOT do a measure when the parent is hidden', done => {
|
||||
charMeasure.measure({});
|
||||
setTimeout(() => {
|
||||
const firstWidth = charMeasure.width;
|
||||
container.style.display = 'none';
|
||||
container.style.fontSize = '2em';
|
||||
charMeasure.measure({});
|
||||
assert.equal(charMeasure.width, firstWidth);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ICharMeasure, ITerminalOptions } from '../Types';
|
||||
import { EventEmitter } from '../EventEmitter';
|
||||
|
||||
/**
|
||||
* Utility class that measures the size of a character. Measurements are done in
|
||||
* the DOM rather than with a canvas context because support for extracting the
|
||||
* height of characters is patchy across browsers.
|
||||
*/
|
||||
export class CharMeasure extends EventEmitter implements ICharMeasure {
|
||||
private _document: Document;
|
||||
private _parentElement: HTMLElement;
|
||||
private _measureElement: HTMLElement;
|
||||
private _width: number;
|
||||
private _height: number;
|
||||
|
||||
constructor(document: Document, parentElement: HTMLElement) {
|
||||
super();
|
||||
this._document = document;
|
||||
this._parentElement = parentElement;
|
||||
this._measureElement = this._document.createElement('span');
|
||||
this._measureElement.classList.add('xterm-char-measure-element');
|
||||
this._measureElement.textContent = 'W';
|
||||
this._measureElement.setAttribute('aria-hidden', 'true');
|
||||
this._parentElement.appendChild(this._measureElement);
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public measure(options: ITerminalOptions): void {
|
||||
this._measureElement.style.fontFamily = options.fontFamily;
|
||||
this._measureElement.style.fontSize = `${options.fontSize}px`;
|
||||
const geometry = this._measureElement.getBoundingClientRect();
|
||||
// The element is likely currently display:none, we should retain the
|
||||
// previous value.
|
||||
if (geometry.width === 0 || geometry.height === 0) {
|
||||
return;
|
||||
}
|
||||
if (this._width !== geometry.width || this._height !== geometry.height) {
|
||||
this._width = geometry.width;
|
||||
this._height = Math.ceil(geometry.height);
|
||||
this.emit('charsizechanged');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { CircularList } from './CircularList';
|
||||
|
||||
describe('CircularList', () => {
|
||||
describe('push', () => {
|
||||
it('should push values onto the array', () => {
|
||||
const list = new CircularList<string>(5);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
list.push('3');
|
||||
list.push('4');
|
||||
list.push('5');
|
||||
assert.equal(list.get(0), '1');
|
||||
assert.equal(list.get(1), '2');
|
||||
assert.equal(list.get(2), '3');
|
||||
assert.equal(list.get(3), '4');
|
||||
assert.equal(list.get(4), '5');
|
||||
});
|
||||
|
||||
it('should push old values from the start out of the array when max length is reached', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
assert.equal(list.get(0), '1');
|
||||
assert.equal(list.get(1), '2');
|
||||
list.push('3');
|
||||
assert.equal(list.get(0), '2');
|
||||
assert.equal(list.get(1), '3');
|
||||
list.push('4');
|
||||
assert.equal(list.get(0), '3');
|
||||
assert.equal(list.get(1), '4');
|
||||
});
|
||||
});
|
||||
|
||||
describe('maxLength', () => {
|
||||
it('should increase the size of the list', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
assert.equal(list.get(0), '1');
|
||||
assert.equal(list.get(1), '2');
|
||||
list.maxLength = 4;
|
||||
list.push('3');
|
||||
list.push('4');
|
||||
assert.equal(list.get(0), '1');
|
||||
assert.equal(list.get(1), '2');
|
||||
assert.equal(list.get(2), '3');
|
||||
assert.equal(list.get(3), '4');
|
||||
list.push('wrapped');
|
||||
assert.equal(list.get(0), '2');
|
||||
assert.equal(list.get(1), '3');
|
||||
assert.equal(list.get(2), '4');
|
||||
assert.equal(list.get(3), 'wrapped');
|
||||
});
|
||||
|
||||
it('should return the maximum length of the list', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
assert.equal(list.maxLength, 2);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
assert.equal(list.maxLength, 2);
|
||||
list.push('3');
|
||||
assert.equal(list.maxLength, 2);
|
||||
list.maxLength = 4;
|
||||
assert.equal(list.maxLength, 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('length', () => {
|
||||
it('should return the current length of the list, capped at the maximum length', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
assert.equal(list.length, 0);
|
||||
list.push('1');
|
||||
assert.equal(list.length, 1);
|
||||
list.push('2');
|
||||
assert.equal(list.length, 2);
|
||||
list.push('3');
|
||||
assert.equal(list.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('splice', () => {
|
||||
it('should delete items', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
list.splice(0, 1);
|
||||
assert.equal(list.length, 1);
|
||||
assert.equal(list.get(0), '2');
|
||||
list.push('3');
|
||||
list.splice(1, 1);
|
||||
assert.equal(list.length, 1);
|
||||
assert.equal(list.get(0), '2');
|
||||
});
|
||||
|
||||
it('should insert items', () => {
|
||||
const list = new CircularList<string>(2);
|
||||
list.push('1');
|
||||
list.splice(0, 0, '2');
|
||||
assert.equal(list.length, 2);
|
||||
assert.equal(list.get(0), '2');
|
||||
assert.equal(list.get(1), '1');
|
||||
list.splice(1, 0, '3');
|
||||
assert.equal(list.length, 2);
|
||||
assert.equal(list.get(0), '3');
|
||||
assert.equal(list.get(1), '1');
|
||||
});
|
||||
|
||||
it('should delete items then insert items', () => {
|
||||
const list = new CircularList<string>(3);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
list.splice(0, 1, '3', '4');
|
||||
assert.equal(list.length, 3);
|
||||
assert.equal(list.get(0), '3');
|
||||
assert.equal(list.get(1), '4');
|
||||
assert.equal(list.get(2), '2');
|
||||
});
|
||||
|
||||
it('should wrap the array correctly when more items are inserted than deleted', () => {
|
||||
const list = new CircularList<string>(3);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
list.splice(1, 0, '3', '4');
|
||||
assert.equal(list.length, 3);
|
||||
assert.equal(list.get(0), '3');
|
||||
assert.equal(list.get(1), '4');
|
||||
assert.equal(list.get(2), '2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('trimStart', () => {
|
||||
it('should remove items from the beginning of the list', () => {
|
||||
const list = new CircularList<string>(5);
|
||||
list.push('1');
|
||||
list.push('2');
|
||||
list.push('3');
|
||||
list.push('4');
|
||||
list.push('5');
|
||||
list.trimStart(1);
|
||||
assert.equal(list.length, 4);
|
||||
assert.deepEqual(list.get(0), '2');
|
||||
assert.deepEqual(list.get(1), '3');
|
||||
assert.deepEqual(list.get(2), '4');
|
||||
assert.deepEqual(list.get(3), '5');
|
||||
list.trimStart(2);
|
||||
assert.equal(list.length, 2);
|
||||
assert.deepEqual(list.get(0), '4');
|
||||
assert.deepEqual(list.get(1), '5');
|
||||
});
|
||||
|
||||
it('should remove all items if the requested trim amount is larger than the list\'s length', () => {
|
||||
const list = new CircularList<string>(5);
|
||||
list.push('1');
|
||||
list.trimStart(2);
|
||||
assert.equal(list.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shiftElements', () => {
|
||||
it('should not mutate the list when count is 0', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.shiftElements(0, 0, 1);
|
||||
assert.equal(list.length, 2);
|
||||
assert.equal(list.get(0), 1);
|
||||
assert.equal(list.get(1), 2);
|
||||
});
|
||||
|
||||
it('should throw for invalid args', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
assert.throws(() => list.shiftElements(-1, 1, 1), 'start argument out of range');
|
||||
assert.throws(() => list.shiftElements(1, 1, 1), 'start argument out of range');
|
||||
assert.throws(() => list.shiftElements(0, 1, -1), 'Cannot shift elements in list beyond index 0');
|
||||
});
|
||||
|
||||
it('should shift an element forward', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.shiftElements(0, 1, 1);
|
||||
assert.equal(list.length, 2);
|
||||
assert.equal(list.get(0), 1);
|
||||
assert.equal(list.get(1), 1);
|
||||
});
|
||||
|
||||
it('should shift elements forward', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
list.shiftElements(0, 2, 2);
|
||||
assert.equal(list.length, 4);
|
||||
assert.equal(list.get(0), 1);
|
||||
assert.equal(list.get(1), 2);
|
||||
assert.equal(list.get(2), 1);
|
||||
assert.equal(list.get(3), 2);
|
||||
});
|
||||
|
||||
it('should shift elements forward, expanding the list if needed', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.shiftElements(0, 2, 2);
|
||||
assert.equal(list.length, 4);
|
||||
assert.equal(list.get(0), 1);
|
||||
assert.equal(list.get(1), 2);
|
||||
assert.equal(list.get(2), 1);
|
||||
assert.equal(list.get(3), 2);
|
||||
});
|
||||
|
||||
it('should shift elements forward, wrapping the list if needed', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
list.push(5);
|
||||
list.shiftElements(2, 2, 3);
|
||||
assert.equal(list.length, 5);
|
||||
assert.equal(list.get(0), 3);
|
||||
assert.equal(list.get(1), 4);
|
||||
assert.equal(list.get(2), 5);
|
||||
assert.equal(list.get(3), 3);
|
||||
assert.equal(list.get(4), 4);
|
||||
});
|
||||
|
||||
it('should shift an element backwards', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.shiftElements(1, 1, -1);
|
||||
assert.equal(list.length, 2);
|
||||
assert.equal(list.get(0), 2);
|
||||
assert.equal(list.get(1), 2);
|
||||
});
|
||||
|
||||
it('should shift elements backwards', () => {
|
||||
const list = new CircularList<number>(5);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
list.shiftElements(2, 2, -2);
|
||||
assert.equal(list.length, 4);
|
||||
assert.equal(list.get(0), 3);
|
||||
assert.equal(list.get(1), 4);
|
||||
assert.equal(list.get(2), 3);
|
||||
assert.equal(list.get(3), 4);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,203 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { EventEmitter } from '../EventEmitter';
|
||||
import { ICircularList } from '../Types';
|
||||
|
||||
/**
|
||||
* Represents a circular list; a list with a maximum size that wraps around when push is called,
|
||||
* overriding values at the start of the list.
|
||||
*/
|
||||
export class CircularList<T> extends EventEmitter implements ICircularList<T> {
|
||||
protected _array: T[];
|
||||
private _startIndex: number;
|
||||
private _length: number;
|
||||
|
||||
constructor(
|
||||
private _maxLength: number
|
||||
) {
|
||||
super();
|
||||
this._array = new Array<T>(this._maxLength);
|
||||
this._startIndex = 0;
|
||||
this._length = 0;
|
||||
}
|
||||
|
||||
public get maxLength(): number {
|
||||
return this._maxLength;
|
||||
}
|
||||
|
||||
public set maxLength(newMaxLength: number) {
|
||||
// There was no change in maxLength, return early.
|
||||
if (this._maxLength === newMaxLength) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reconstruct array, starting at index 0. Only transfer values from the
|
||||
// indexes 0 to length.
|
||||
const newArray = new Array<T>(newMaxLength);
|
||||
for (let i = 0; i < Math.min(newMaxLength, this.length); i++) {
|
||||
newArray[i] = this._array[this._getCyclicIndex(i)];
|
||||
}
|
||||
this._array = newArray;
|
||||
this._maxLength = newMaxLength;
|
||||
this._startIndex = 0;
|
||||
}
|
||||
|
||||
public get length(): number {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
public set length(newLength: number) {
|
||||
if (newLength > this._length) {
|
||||
for (let i = this._length; i < newLength; i++) {
|
||||
this._array[i] = undefined;
|
||||
}
|
||||
}
|
||||
this._length = newLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value at an index.
|
||||
*
|
||||
* Note that for performance reasons there is no bounds checking here, the index reference is
|
||||
* circular so this should always return a value and never throw.
|
||||
* @param index The index of the value to get.
|
||||
* @return The value corresponding to the index.
|
||||
*/
|
||||
public get(index: number): T {
|
||||
return this._array[this._getCyclicIndex(index)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value at an index.
|
||||
*
|
||||
* Note that for performance reasons there is no bounds checking here, the index reference is
|
||||
* circular so this should always return a value and never throw.
|
||||
* @param index The index to set.
|
||||
* @param value The value to set.
|
||||
*/
|
||||
public set(index: number, value: T): void {
|
||||
this._array[this._getCyclicIndex(index)] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a new value onto the list, wrapping around to the start of the array, overriding index 0
|
||||
* if the maximum length is reached.
|
||||
* @param value The value to push onto the list.
|
||||
*/
|
||||
public push(value: T): void {
|
||||
this._array[this._getCyclicIndex(this._length)] = value;
|
||||
if (this._length === this._maxLength) {
|
||||
this._startIndex++;
|
||||
if (this._startIndex === this._maxLength) {
|
||||
this._startIndex = 0;
|
||||
}
|
||||
this.emit('trim', 1);
|
||||
} else {
|
||||
this._length++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns the last value on the list.
|
||||
* @return The popped value.
|
||||
*/
|
||||
public pop(): T {
|
||||
return this._array[this._getCyclicIndex(this._length-- - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes and/or inserts items at a particular index (in that order). Unlike
|
||||
* Array.prototype.splice, this operation does not return the deleted items as a new array in
|
||||
* order to save creating a new array. Note that this operation may shift all values in the list
|
||||
* in the worst case.
|
||||
* @param start The index to delete and/or insert.
|
||||
* @param deleteCount The number of elements to delete.
|
||||
* @param items The items to insert.
|
||||
*/
|
||||
public splice(start: number, deleteCount: number, ...items: T[]): void {
|
||||
// Delete items
|
||||
if (deleteCount) {
|
||||
for (let i = start; i < this._length - deleteCount; i++) {
|
||||
this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
|
||||
}
|
||||
this._length -= deleteCount;
|
||||
}
|
||||
|
||||
if (items && items.length) {
|
||||
// Add items
|
||||
for (let i = this._length - 1; i >= start; i--) {
|
||||
this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
|
||||
}
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
this._array[this._getCyclicIndex(start + i)] = items[i];
|
||||
}
|
||||
|
||||
// Adjust length as needed
|
||||
if (this._length + items.length > this.maxLength) {
|
||||
const countToTrim = (this._length + items.length) - this.maxLength;
|
||||
this._startIndex += countToTrim;
|
||||
this._length = this.maxLength;
|
||||
this.emit('trim', countToTrim);
|
||||
} else {
|
||||
this._length += items.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims a number of items from the start of the list.
|
||||
* @param count The number of items to remove.
|
||||
*/
|
||||
public trimStart(count: number): void {
|
||||
if (count > this._length) {
|
||||
count = this._length;
|
||||
}
|
||||
this._startIndex += count;
|
||||
this._length -= count;
|
||||
this.emit('trim', count);
|
||||
}
|
||||
|
||||
public shiftElements(start: number, count: number, offset: number): void {
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
if (start < 0 || start >= this._length) {
|
||||
throw new Error('start argument out of range');
|
||||
}
|
||||
if (start + offset < 0) {
|
||||
throw new Error('Cannot shift elements in list beyond index 0');
|
||||
}
|
||||
|
||||
if (offset > 0) {
|
||||
for (let i = count - 1; i >= 0; i--) {
|
||||
this.set(start + i + offset, this.get(start + i));
|
||||
}
|
||||
const expandListBy = (start + count + offset) - this._length;
|
||||
if (expandListBy > 0) {
|
||||
this._length += expandListBy;
|
||||
while (this._length > this.maxLength) {
|
||||
this._length--;
|
||||
this._startIndex++;
|
||||
this.emit('trim', 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.set(start + i + offset, this.get(start + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cyclic index for the specified regular index. The cyclic index can then be used on the
|
||||
* backing array to get the element associated with the regular index.
|
||||
* @param index The regular index.
|
||||
* @returns The cyclic index.
|
||||
*/
|
||||
private _getCyclicIndex(index: number): number {
|
||||
return (this._startIndex + index) % this.maxLength;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ describe('clone', () => {
|
||||
});
|
||||
|
||||
it('should clone null values', () => {
|
||||
const test = {
|
||||
const test: any = {
|
||||
a: null
|
||||
};
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IDisposable } from 'xterm';
|
||||
|
||||
/**
|
||||
* Adds a disposabe listener to a node in the DOM, returning the disposable.
|
||||
* @param type The event type.
|
||||
* @param handler The handler for the listener.
|
||||
*/
|
||||
export function addDisposableListener(
|
||||
node: Element | Window | Document,
|
||||
type: string,
|
||||
handler: (e: any) => void,
|
||||
useCapture?: boolean
|
||||
): IDisposable {
|
||||
node.addEventListener(type, handler, useCapture);
|
||||
return {
|
||||
dispose: () => {
|
||||
if (!handler) {
|
||||
// Already disposed
|
||||
return;
|
||||
}
|
||||
node.removeEventListener(type, handler, useCapture);
|
||||
node = null;
|
||||
handler = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import { ITerminal } from '../Types';
|
||||
import { IDisposable } from 'xterm';
|
||||
|
||||
/**
|
||||
* Debounces calls to render terminal rows using animation frames.
|
||||
*/
|
||||
export class RenderDebouncer implements IDisposable {
|
||||
private _rowStart: number;
|
||||
private _rowEnd: number;
|
||||
private _animationFrame: number = null;
|
||||
|
||||
constructor(
|
||||
private _terminal: ITerminal,
|
||||
private _callback: (start: number, end: number) => void
|
||||
) {
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this._animationFrame) {
|
||||
window.cancelAnimationFrame(this._animationFrame);
|
||||
this._animationFrame = null;
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(rowStart?: number, rowEnd?: number): void {
|
||||
rowStart = rowStart || 0;
|
||||
rowEnd = rowEnd || this._terminal.rows - 1;
|
||||
this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
|
||||
this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
|
||||
|
||||
if (this._animationFrame) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._animationFrame = window.requestAnimationFrame(() => this._innerRefresh());
|
||||
}
|
||||
|
||||
private _innerRefresh(): void {
|
||||
// Clamp values
|
||||
this._rowStart = Math.max(this._rowStart, 0);
|
||||
this._rowEnd = Math.min(this._rowEnd, this._terminal.rows - 1);
|
||||
|
||||
// Run render callback
|
||||
this._callback(this._rowStart, this._rowEnd);
|
||||
|
||||
// Reset debouncer
|
||||
this._rowStart = null;
|
||||
this._rowEnd = null;
|
||||
this._animationFrame = null;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
export type ScreenDprListener = (newDevicePixelRatio?: number, oldDevicePixelRatio?: number) => void;
|
||||
|
||||
/**
|
||||
* The screen device pixel ratio monitor allows listening for when the
|
||||
* window.devicePixelRatio value changes. This is done not with polling but with
|
||||
* the use of window.matchMedia to watch media queries. When the event fires,
|
||||
* the listener will be reattached using a different media query to ensure that
|
||||
* any further changes will register.
|
||||
*
|
||||
* The listener should fire on both window zoom changes and switching to a
|
||||
* monitor with a different DPI.
|
||||
*/
|
||||
export class ScreenDprMonitor {
|
||||
private _currentDevicePixelRatio: number;
|
||||
private _outerListener: MediaQueryListListener;
|
||||
private _listener: ScreenDprListener;
|
||||
private _resolutionMediaMatchList: MediaQueryList;
|
||||
|
||||
public setListener(listener: ScreenDprListener): void {
|
||||
if (this._listener) {
|
||||
this.clearListener();
|
||||
}
|
||||
this._listener = listener;
|
||||
this._outerListener = () => {
|
||||
this._listener(window.devicePixelRatio, this._currentDevicePixelRatio);
|
||||
this._updateDpr();
|
||||
};
|
||||
this._updateDpr();
|
||||
}
|
||||
|
||||
private _updateDpr(): void {
|
||||
// Clear listeners for old DPR
|
||||
if (this._resolutionMediaMatchList) {
|
||||
this._resolutionMediaMatchList.removeListener(this._outerListener);
|
||||
}
|
||||
// Add listeners for new DPR
|
||||
this._currentDevicePixelRatio = window.devicePixelRatio;
|
||||
this._resolutionMediaMatchList = window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);
|
||||
this._resolutionMediaMatchList.addListener(this._outerListener);
|
||||
}
|
||||
|
||||
public clearListener(): void {
|
||||
if (!this._listener) {
|
||||
return;
|
||||
}
|
||||
this._resolutionMediaMatchList.removeListener(this._outerListener);
|
||||
this._listener = null;
|
||||
this._outerListener = null;
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,6 @@ export class MockTerminal implements ITerminal {
|
||||
children: HTMLElement[];
|
||||
cursorHidden: boolean;
|
||||
cursorState: number;
|
||||
defAttr: number;
|
||||
scrollback: number;
|
||||
buffers: IBufferSet;
|
||||
buffer: IBuffer;
|
||||
@@ -184,8 +183,8 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal {
|
||||
insertMode: boolean;
|
||||
wraparoundMode: boolean;
|
||||
bracketedPasteMode: boolean;
|
||||
defAttr: number;
|
||||
curAttr: number;
|
||||
savedCurAttr: number;
|
||||
savedCols: number;
|
||||
x10Mouse: boolean;
|
||||
vt200Mouse: boolean;
|
||||
@@ -269,7 +268,7 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
setOption(key: string, value: any): void {
|
||||
this.options[key] = value;
|
||||
(<any>this.options)[key] = value;
|
||||
}
|
||||
on(type: string, listener: XtermListener): void {
|
||||
throw new Error('Method not implemented.');
|
||||
@@ -304,6 +303,9 @@ export class MockBuffer implements IBuffer {
|
||||
translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol?: number, endCol?: number): string {
|
||||
return Buffer.prototype.translateBufferLineToString.apply(this, arguments);
|
||||
}
|
||||
getWrappedRangeForLine(y: number): { first: number; last: number; } {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
nextStop(x?: number): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
@@ -316,6 +318,9 @@ export class MockBuffer implements IBuffer {
|
||||
}
|
||||
|
||||
export class MockRenderer implements IRenderer {
|
||||
dispose(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
colorManager: IColorManager;
|
||||
on(type: string, listener: XtermListener): void {
|
||||
throw new Error('Method not implemented.');
|
||||
@@ -346,6 +351,9 @@ export class MockRenderer implements IRenderer {
|
||||
}
|
||||
|
||||
export class MockViewport implements IViewport {
|
||||
dispose(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
scrollBarWidth: number = 0;
|
||||
onThemeChanged(colors: IColorSet): void {
|
||||
throw new Error('Method not implemented.');
|
||||
|
||||
Reference in New Issue
Block a user