Merge pull request #4364 from Tyriar/dom_remove
Replace dom helper with HTMLElement.remove()
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { removeElementFromParent } from 'browser/Dom';
|
|
||||||
import { acquireTextureAtlas } from 'browser/renderer/shared/CharAtlasCache';
|
import { acquireTextureAtlas } from 'browser/renderer/shared/CharAtlasCache';
|
||||||
import { TEXT_BASELINE } from 'browser/renderer/shared/Constants';
|
import { TEXT_BASELINE } from 'browser/renderer/shared/Constants';
|
||||||
import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs';
|
import { tryDrawCustomChar } from 'browser/renderer/shared/CustomGlyphs';
|
||||||
@@ -74,7 +73,7 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this.register(toDisposable(() => {
|
this.register(toDisposable(() => {
|
||||||
removeElementFromParent(this._canvas);
|
this._canvas.remove();
|
||||||
this._charAtlas?.dispose();
|
this._charAtlas?.dispose();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import { addDisposableDomListener } from 'browser/Lifecycle';
|
|||||||
import { Disposable, toDisposable } from 'common/Lifecycle';
|
import { Disposable, toDisposable } from 'common/Lifecycle';
|
||||||
import { ScreenDprMonitor } from 'browser/ScreenDprMonitor';
|
import { ScreenDprMonitor } from 'browser/ScreenDprMonitor';
|
||||||
import { IRenderService } from 'browser/services/Services';
|
import { IRenderService } from 'browser/services/Services';
|
||||||
import { removeElementFromParent } from 'browser/Dom';
|
|
||||||
|
|
||||||
const MAX_ROWS_TO_READ = 20;
|
const MAX_ROWS_TO_READ = 20;
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ export class AccessibilityManager extends Disposable {
|
|||||||
// media query that drives the ScreenDprMonitor isn't supported
|
// media query that drives the ScreenDprMonitor isn't supported
|
||||||
this.register(addDisposableDomListener(window, 'resize', () => this._refreshRowsDimensions()));
|
this.register(addDisposableDomListener(window, 'resize', () => this._refreshRowsDimensions()));
|
||||||
this.register(toDisposable(() => {
|
this.register(toDisposable(() => {
|
||||||
removeElementFromParent(this._accessibilityTreeRoot);
|
this._accessibilityTreeRoot.remove();
|
||||||
this._rowElements.length = 0;
|
this._rowElements.length = 0;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -240,7 +239,7 @@ export class AccessibilityManager extends Disposable {
|
|||||||
|
|
||||||
// Only detach/attach on mac as otherwise messages can go unaccounced
|
// Only detach/attach on mac as otherwise messages can go unaccounced
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
removeElementFromParent(this._liveRegion);
|
this._liveRegion.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2020 The xterm.js authors. All rights reserved.
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
import jsdom = require('jsdom');
|
|
||||||
import { removeElementFromParent } from 'browser/Dom';
|
|
||||||
import { strictEqual, doesNotThrow } from 'assert';
|
|
||||||
|
|
||||||
describe('Dom', () => {
|
|
||||||
const dom = new jsdom.JSDOM();
|
|
||||||
const document = dom.window.document;
|
|
||||||
|
|
||||||
describe('removeElementFromParent', () => {
|
|
||||||
it('should remove single child', () => {
|
|
||||||
const e = document.createElement('div');
|
|
||||||
document.body.appendChild(e);
|
|
||||||
strictEqual(e.parentElement, document.body);
|
|
||||||
removeElementFromParent(e);
|
|
||||||
strictEqual(e.parentElement, null);
|
|
||||||
});
|
|
||||||
it('should remove multiple elements', () => {
|
|
||||||
const e1 = document.createElement('div');
|
|
||||||
const e2 = document.createElement('div');
|
|
||||||
document.body.appendChild(e1);
|
|
||||||
document.body.appendChild(e2);
|
|
||||||
strictEqual(e1.parentElement, document.body);
|
|
||||||
strictEqual(e2.parentElement, document.body);
|
|
||||||
removeElementFromParent(e1, e2);
|
|
||||||
strictEqual(e1.parentElement, null);
|
|
||||||
strictEqual(e2.parentElement, null);
|
|
||||||
});
|
|
||||||
it('should not throw on undefined', () => {
|
|
||||||
const e = document.createElement('div');
|
|
||||||
document.body.appendChild(e);
|
|
||||||
strictEqual(e.parentElement, document.body);
|
|
||||||
doesNotThrow(() => removeElementFromParent(undefined, e));
|
|
||||||
strictEqual(e.parentElement, null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2020 The xterm.js authors. All rights reserved.
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function removeElementFromParent(...elements: (HTMLElement | undefined)[]): void {
|
|
||||||
for (const e of elements) {
|
|
||||||
e?.parentElement?.removeChild(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { removeElementFromParent } from 'browser/Dom';
|
|
||||||
import { BOLD_CLASS, CURSOR_BLINK_CLASS, CURSOR_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory, ITALIC_CLASS } from 'browser/renderer/dom/DomRendererRowFactory';
|
import { BOLD_CLASS, CURSOR_BLINK_CLASS, CURSOR_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory, ITALIC_CLASS } from 'browser/renderer/dom/DomRendererRowFactory';
|
||||||
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants';
|
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants';
|
||||||
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
|
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
|
||||||
@@ -87,7 +86,10 @@ export class DomRenderer extends Disposable implements IRenderer {
|
|||||||
|
|
||||||
// Outside influences such as React unmounts may manipulate the DOM before our disposal.
|
// Outside influences such as React unmounts may manipulate the DOM before our disposal.
|
||||||
// https://github.com/xtermjs/xterm.js/issues/2960
|
// https://github.com/xtermjs/xterm.js/issues/2960
|
||||||
removeElementFromParent(this._rowContainer, this._selectionContainer, this._themeStyleElement, this._dimensionsStyleElement);
|
this._rowContainer.remove();
|
||||||
|
this._selectionContainer.remove();
|
||||||
|
this._themeStyleElement.remove();
|
||||||
|
this._dimensionsStyleElement.remove();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user