Merge branch 'master' into 1593_column_select

This commit is contained in:
Daniel Imms
2018-08-06 11:17:52 -07:00
committed by GitHub
4 changed files with 62 additions and 0 deletions
+5
View File
@@ -296,6 +296,11 @@ export class InputHandler extends Disposable implements IInputHandler {
}
public parse(data: string): void {
// Ensure the terminal is not disposed
if (!this._terminal) {
return;
}
let buffer = this._terminal.buffer;
const cursorStartX = buffer.x;
const cursorStartY = buffer.y;
+10
View File
@@ -1293,6 +1293,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
* @param data The text to write to the terminal.
*/
public write(data: string): void {
// Ensure the terminal isn't disposed
if (this._isDisposed) {
return;
}
// Ignore falsy data values (including the empty string)
if (!data) {
return;
@@ -1321,6 +1326,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
}
protected _innerWrite(): void {
// Ensure the terminal isn't disposed
if (this._isDisposed) {
this.writeBuffer = [];
}
const writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
while (writeBatch.length > 0) {
const data = writeBatch.shift();
+45
View File
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { assert } from 'chai';
import { Disposable } from './Lifecycle';
class TestDisposable extends Disposable {
public get isDisposed(): boolean {
return this._isDisposed;
}
}
describe('Disposable', () => {
describe('register', () => {
it('should register disposables', () => {
const d = new TestDisposable();
const d2 = {
dispose: () => { throw new Error(); }
};
d.register(d2);
assert.throws(() => d.dispose());
});
});
describe('unregister', () => {
it('should unregister disposables', () => {
const d = new TestDisposable();
const d2 = {
dispose: () => { throw new Error(); }
};
d.register(d2);
d.unregister(d2);
assert.doesNotThrow(() => d.dispose());
});
});
describe('dispose', () => {
it('should set is disposed flag', () => {
const d = new TestDisposable();
assert.isFalse(d.isDisposed);
d.dispose();
assert.isTrue(d.isDisposed);
});
});
});
+2
View File
@@ -11,6 +11,7 @@ import { IDisposable } from 'xterm';
*/
export abstract class Disposable implements IDisposable {
protected _disposables: IDisposable[] = [];
protected _isDisposed: boolean = false;
constructor() {
}
@@ -19,6 +20,7 @@ export abstract class Disposable implements IDisposable {
* Disposes the object, triggering the `dispose` method on all registered IDisposables.
*/
public dispose(): void {
this._isDisposed = true;
this._disposables.forEach(d => d.dispose());
this._disposables.length = 0;
}