From d0e05eb795c6ab4a22b3dc00ffb3f2e6e8de3e80 Mon Sep 17 00:00:00 2001 From: Revanth Mahesh Date: Sun, 27 Oct 2019 10:11:43 +0530 Subject: [PATCH 1/9] Support disposing of EventEmitters --- src/common/EventEmitter.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/EventEmitter.ts b/src/common/EventEmitter.ts index 34ac190f15..ea9df48bee 100644 --- a/src/common/EventEmitter.ts +++ b/src/common/EventEmitter.ts @@ -16,11 +16,13 @@ export interface IEvent { export interface IEventEmitter { event: IEvent; fire(data: T): void; + dispose(): void; } export class EventEmitter implements IEventEmitter { private _listeners: IListener[] = []; private _event?: IEvent; + private _disposed: boolean = false; public get event(): IEvent { if (!this._event) { @@ -28,10 +30,12 @@ export class EventEmitter implements IEventEmitter { this._listeners.push(listener); const disposable = { dispose: () => { - for (let i = 0; i < this._listeners.length; i++) { - if (this._listeners[i] === listener) { - this._listeners.splice(i, 1); - return; + if (!this._disposed) { + for (let i = 0; i < this._listeners.length; i++) { + if (this._listeners[i] === listener) { + this._listeners.splice(i, 1); + return; + } } } } @@ -51,4 +55,12 @@ export class EventEmitter implements IEventEmitter { queue[i].call(undefined, data); } } + +public dispose(): void { + if (this._listeners) { + this._listeners.splice(0, this._listeners.length); + } + this._disposed = true; +} + } From f3bbcb35e4421c112d81f66f0ea1f3286e8e5ed4 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 26 Oct 2019 21:52:11 -0700 Subject: [PATCH 2/9] Clean up --- src/common/EventEmitter.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/EventEmitter.ts b/src/common/EventEmitter.ts index ea9df48bee..5991e338d1 100644 --- a/src/common/EventEmitter.ts +++ b/src/common/EventEmitter.ts @@ -56,11 +56,10 @@ export class EventEmitter implements IEventEmitter { } } -public dispose(): void { - if (this._listeners) { - this._listeners.splice(0, this._listeners.length); + public dispose(): void { + if (this._listeners) { + this._listeners.length = 0; + } + this._disposed = true; } - this._disposed = true; -} - } From 56d33668310397948dcfeb6324ac1d518ebb11bf Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:08:42 +0100 Subject: [PATCH 3/9] Fix typo --- addons/xterm-addon-search/typings/xterm-addon-search.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts index 94bc529718..913f33dfe9 100644 --- a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts +++ b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts @@ -27,7 +27,7 @@ declare module 'xterm-addon-search' { caseSensitive?: boolean; /** - * Whether to do an indcremental search, this will expand the selection if it + * Whether to do an incremental search, this will expand the selection if it * still matches the term the user typed. Note that this only affects * `findNext`, not `findPrevious`. */ From dca1e0b93549a155fef5b6e82532f6be6552957f Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:18:11 +0100 Subject: [PATCH 4/9] Fix another typo --- addons/xterm-addon-search/typings/xterm-addon-search.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts index 913f33dfe9..f27aba7834 100644 --- a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts +++ b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts @@ -17,7 +17,7 @@ declare module 'xterm-addon-search' { /** * Whether to search for a whole word, the result is only valid if it's - * suppounded in "non-word" characters such as `_`, `(`, `)` or space. + * surrounded in "non-word" characters such as `_`, `(`, `)` or space. */ wholeWord?: boolean; From 8d0fdc8731b823968e991eb8b98588f5577407ab Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:29:36 +0100 Subject: [PATCH 5/9] Fix grammar --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 295a03b278..27f3917712 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -49,7 +49,7 @@ declare module 'xterm' { /** * When enabled the cursor will be set to the beginning of the next line - * with every new line. This equivalent to sending '\r\n' for each '\n'. + * with every new line. This is equivalent to sending '\r\n' for each '\n'. * Normally the termios settings of the underlying PTY deals with the * translation of '\n' to '\r\n' and this setting should not be used. If you * deal with data from a non-PTY related source, this settings might be From fe2ac04b857e730f62780e55ebf1d672890510b7 Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:34:54 +0100 Subject: [PATCH 6/9] Fix grammar --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 27f3917712..eb9904e896 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -437,7 +437,7 @@ declare module 'xterm' { onData: IEvent; /** - * Adds an event listener for a key is pressed. The event value contains the + * Adds an event listener for when a key is pressed. The event value contains the * string that will be sent in the data event as well as the DOM event that * triggered it. * @returns an `IDisposable` to stop listening. From ffe2d66affe663c5bb861a92c28517f19e90c5be Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:38:55 +0100 Subject: [PATCH 7/9] Remove duplicated punctuation --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index eb9904e896..9ec407c722 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -609,7 +609,7 @@ declare module 'xterm' { /** * Selects text within the terminal. - * @param column The column the selection starts at.. + * @param column The column the selection starts at. * @param row The row the selection starts at. * @param length The length of the selection. */ From b880cd3ad3d171023bcb11caf708f6ec7d7c1f6c Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:43:26 +0100 Subject: [PATCH 8/9] Fix punctuation mark --- typings/xterm.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 9ec407c722..eb2b3a7f78 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -918,7 +918,7 @@ declare module 'xterm' { /** * The line within the buffer where the top of the bottom page is (when - * fully scrolled down); + * fully scrolled down). */ readonly baseY: number; From cb1cf3cd119d500d5ac099548a5d5394fc061e03 Mon Sep 17 00:00:00 2001 From: alberto Date: Sun, 27 Oct 2019 22:50:22 +0100 Subject: [PATCH 9/9] Fix grammar --- typings/xterm.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index eb2b3a7f78..9728a72cb5 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -1047,7 +1047,7 @@ declare module 'xterm' { * array will contain subarrays with their numercial values. * Return true if the sequence was handled; false if we should try * a previous handler (set by addCsiHandler or setCsiHandler). - * The most recently-added handler is tried first. + * The most recently added handler is tried first. * @return An IDisposable you can call to remove this handler. */ addCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean): IDisposable; @@ -1066,7 +1066,7 @@ declare module 'xterm' { * The function gets the payload and numerical parameters as arguments. * Return true if the sequence was handled; false if we should try * a previous handler (set by addDcsHandler or setDcsHandler). - * The most recently-added handler is tried first. + * The most recently added handler is tried first. * @return An IDisposable you can call to remove this handler. */ addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean): IDisposable; @@ -1079,7 +1079,7 @@ declare module 'xterm' { * @param callback The function to handle the sequence. * Return true if the sequence was handled; false if we should try * a previous handler (set by addEscHandler or setEscHandler). - * The most recently-added handler is tried first. + * The most recently added handler is tried first. * @return An IDisposable you can call to remove this handler. */ addEscHandler(id: IFunctionIdentifier, handler: () => boolean): IDisposable; @@ -1097,7 +1097,7 @@ declare module 'xterm' { * The callback is called with OSC data string. * Return true if the sequence was handled; false if we should try * a previous handler (set by addOscHandler or setOscHandler). - * The most recently-added handler is tried first. + * The most recently added handler is tried first. * @return An IDisposable you can call to remove this handler. */ addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;