add a container

This commit is contained in:
meganrogge
2022-02-09 09:55:30 -06:00
parent 8e75cecba3
commit 313cb2fe09
3 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -174,7 +174,7 @@
text-decoration: line-through; text-decoration: line-through;
} }
.xterm-screen .xterm-decoration { .xterm-screen .xterm-decoration-container .xterm-decoration {
z-index: 6; z-index: 6;
position: absolute; position: absolute;
} }
+10 -9
View File
@@ -12,8 +12,7 @@ import { IDecorationOptions, IDecoration, IMarker } from 'xterm';
export class DecorationService extends Disposable implements IDecorationService { export class DecorationService extends Disposable implements IDecorationService {
private readonly _decorations: Decoration[] = []; private readonly _decorations: Decoration[] = [];
private _screenElement: HTMLElement | undefined; private _container: HTMLElement | undefined;
private _renderService: IRenderService | undefined; private _renderService: IRenderService | undefined;
private _bufferService: IBufferService | undefined; private _bufferService: IBufferService | undefined;
@@ -23,18 +22,20 @@ export class DecorationService extends Disposable implements IDecorationService
} }
public attachToDom(screenElement: HTMLElement, renderService: IRenderService, bufferService: IBufferService): void { public attachToDom(screenElement: HTMLElement, renderService: IRenderService, bufferService: IBufferService): void {
this._screenElement = screenElement;
this._renderService = renderService; this._renderService = renderService;
this._bufferService = bufferService; this._bufferService = bufferService;
this._container = document.createElement('div');
this._container.classList.add('xterm-decoration-container');
screenElement.appendChild(this._container);
this.refresh(); this.refresh();
this.register(this._renderService.onRenderedBufferChange(() => this.refresh())); this.register(this._renderService.onRenderedBufferChange(() => this.refresh()));
} }
public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined {
if (decorationOptions.marker.isDisposed || !this._screenElement) { if (decorationOptions.marker.isDisposed || !this._container) {
return undefined; return undefined;
} }
const decoration = new Decoration(decorationOptions, this._screenElement); const decoration = new Decoration(decorationOptions, this._container);
this._decorations.push(decoration); this._decorations.push(decoration);
decoration.onDispose(() => this._decorations.splice(this._decorations.indexOf(decoration), 1)); decoration.onDispose(() => this._decorations.splice(this._decorations.indexOf(decoration), 1));
return decoration; return decoration;
@@ -74,7 +75,7 @@ class Decoration extends Disposable implements IDecoration {
constructor( constructor(
private readonly _decorationOptions: IDecorationOptions, private readonly _decorationOptions: IDecorationOptions,
private readonly _screenElement: HTMLElement private readonly _container: HTMLElement
) { ) {
super(); super();
this._marker = _decorationOptions.marker; this._marker = _decorationOptions.marker;
@@ -84,8 +85,8 @@ class Decoration extends Disposable implements IDecoration {
if (!this._element) { if (!this._element) {
this._createElement(bufferService, renderService); this._createElement(bufferService, renderService);
} }
if (this._screenElement && this._element && !this._screenElement.contains(this._element)) { if (this._container && this._element && !this._container.contains(this._element)) {
this._screenElement.append(this._element); this._container.append(this._element);
} }
this._refreshStyle(bufferService, renderService); this._refreshStyle(bufferService, renderService);
this._onRender.fire(this._element!); this._onRender.fire(this._element!);
@@ -109,7 +110,7 @@ class Decoration extends Disposable implements IDecoration {
if (this.isDisposed) { if (this.isDisposed) {
return; return;
} }
this._screenElement.removeChild(this._element!); this._container.removeChild(this._element!);
this.isDisposed = true; this.isDisposed = true;
this._marker.dispose(); this._marker.dispose();
// Emit before super.dispose such that dispose listeners get a change to react // Emit before super.dispose such that dispose listeners get a change to react
+2 -2
View File
@@ -731,7 +731,7 @@ describe('API Integration Tests', function(): void {
await pollFor(page, `window.term._core._renderService.dimensions.actualCellWidth > 0`, true); await pollFor(page, `window.term._core._renderService.dimensions.actualCellWidth > 0`, true);
}); });
describe('registerDecoration', () => { describe.only('registerDecoration', () => {
it('should register a decoration', async () => { it('should register a decoration', async () => {
await openTerminal(page); await openTerminal(page);
await page.evaluate(`window.marker = window.term.addMarker(1)`); await page.evaluate(`window.marker = window.term.addMarker(1)`);
@@ -756,7 +756,7 @@ describe('API Integration Tests', function(): void {
} }
`); `);
await pollFor(page, 'window.throwMessage', 'This API only accepts positive integers'); await pollFor(page, 'window.throwMessage', 'This API only accepts positive integers');
assert.equal(await page.evaluate(`document.querySelector('.xterm-screen .xterm-decoration')`), undefined); assert.equal(await page.evaluate(`document.querySelector('.xterm-screen .xterm-decoration-container .xterm-decoration')`), undefined);
}); });
}); });