Fix terminal object leaking

This commit is contained in:
Daniel Imms
2020-05-03 12:46:37 -07:00
parent 66b2c01549
commit b75e42a56c
10 changed files with 74 additions and 37 deletions
+20 -3
View File
@@ -31,6 +31,17 @@ import { Unicode11Addon } from '../addons/xterm-addon-unicode11/out/Unicode11Add
// little weird here as we're importing "this" module
import { Terminal as TerminalType, ITerminalOptions } from 'xterm';
interface IDisposable {
dispose(): void;
}
function addDisposableListener(element: HTMLElement, type: string, listener: (event: any) => void): IDisposable {
element.addEventListener(type, listener);
return {
dispose: () => element.removeEventListener(type, listener)
};
}
export interface IWindowWithTerminal extends Window {
term: TerminalType;
Terminal?: typeof TerminalType;
@@ -112,9 +123,15 @@ const disposeRecreateButtonHandler = () => {
term = null;
window.term = null;
socket = null;
addons.attach.instance = undefined;
addons.fit.instance = undefined;
addons.search.instance = undefined;
addons.serialize.instance = undefined;
addons.unicode11.instance = undefined;
addons['web-links'].instance = undefined;
addons.webgl.instance = undefined;
document.getElementById('dispose').innerHTML = 'Recreate Terminal';
}
else {
} else {
createTerminal();
document.getElementById('dispose').innerHTML = 'Dispose terminal';
}
@@ -357,7 +374,7 @@ function initAddons(term: TerminalType): void {
if (!addon.canChange) {
checkbox.disabled = true;
}
checkbox.addEventListener('change', () => {
addDomListener(checkbox, 'change', () => {
if (checkbox.checked) {
addon.instance = new addon.ctor();
term.loadAddon(addon.instance);