Merge branch 'master' into 1593_column_select
This commit is contained in:
@@ -296,6 +296,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public parse(data: string): void {
|
public parse(data: string): void {
|
||||||
|
// Ensure the terminal is not disposed
|
||||||
|
if (!this._terminal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let buffer = this._terminal.buffer;
|
let buffer = this._terminal.buffer;
|
||||||
const cursorStartX = buffer.x;
|
const cursorStartX = buffer.x;
|
||||||
const cursorStartY = buffer.y;
|
const cursorStartY = buffer.y;
|
||||||
|
|||||||
@@ -1293,6 +1293,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
* @param data The text to write to the terminal.
|
* @param data The text to write to the terminal.
|
||||||
*/
|
*/
|
||||||
public write(data: string): void {
|
public write(data: string): void {
|
||||||
|
// Ensure the terminal isn't disposed
|
||||||
|
if (this._isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore falsy data values (including the empty string)
|
// Ignore falsy data values (including the empty string)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
@@ -1321,6 +1326,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected _innerWrite(): void {
|
protected _innerWrite(): void {
|
||||||
|
// Ensure the terminal isn't disposed
|
||||||
|
if (this._isDisposed) {
|
||||||
|
this.writeBuffer = [];
|
||||||
|
}
|
||||||
|
|
||||||
const writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
|
const writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
|
||||||
while (writeBatch.length > 0) {
|
while (writeBatch.length > 0) {
|
||||||
const data = writeBatch.shift();
|
const data = writeBatch.shift();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -11,6 +11,7 @@ import { IDisposable } from 'xterm';
|
|||||||
*/
|
*/
|
||||||
export abstract class Disposable implements IDisposable {
|
export abstract class Disposable implements IDisposable {
|
||||||
protected _disposables: IDisposable[] = [];
|
protected _disposables: IDisposable[] = [];
|
||||||
|
protected _isDisposed: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
@@ -19,6 +20,7 @@ export abstract class Disposable implements IDisposable {
|
|||||||
* Disposes the object, triggering the `dispose` method on all registered IDisposables.
|
* Disposes the object, triggering the `dispose` method on all registered IDisposables.
|
||||||
*/
|
*/
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
|
this._isDisposed = true;
|
||||||
this._disposables.forEach(d => d.dispose());
|
this._disposables.forEach(d => d.dispose());
|
||||||
this._disposables.length = 0;
|
this._disposables.length = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user