Skip to content
Permalink
Browse files
Merge branch 'master' into htmlserialize
  • Loading branch information
meganrogge committed Feb 22, 2022
2 parents 92a61e6 + e08962b commit 365a07968b94a6a0ef27912504d996d875a3a7de
Showing with 51 additions and 38 deletions.
  1. +3 −3 addons/xterm-addon-ligatures/yarn.lock
  2. +35 −30 src/browser/services/DecorationService.ts
  3. +1 −0 src/common/InputHandler.ts
  4. +11 −4 src/common/buffer/Buffer.ts
  5. +1 −1 src/common/buffer/Types.d.ts
@@ -67,9 +67,9 @@ fd-slicer@~1.1.0:
pend "~1.2.0"

follow-redirects@^1.14.0:
version "1.14.7"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685"
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==
version "1.14.8"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==

font-finder@^1.0.3:
version "1.0.4"
@@ -16,19 +16,14 @@ export class DecorationService extends Disposable implements IDecorationService
private _screenElement: HTMLElement | undefined;
private _renderService: IRenderService | undefined;

constructor(
@IBufferService private readonly _bufferService: IBufferService,
@IInstantiationService private readonly _instantiationService: IInstantiationService) {
super();
}
constructor(@IInstantiationService private readonly _instantiationService: IInstantiationService) { super(); }

public attachToDom(screenElement: HTMLElement, renderService: IRenderService): void {
this._renderService = renderService;
this._screenElement = screenElement;
this._container = document.createElement('div');
this._container.classList.add('xterm-decoration-container');
screenElement.appendChild(this._container);
this.refresh();
this.register(this._renderService.onRenderedBufferChange(() => this.refresh()));
this.register(this._renderService.onDimensionsChange(() => this.refresh(true)));
}
@@ -43,29 +38,28 @@ export class DecorationService extends Disposable implements IDecorationService
return decoration;
}

public refresh(recreate?: boolean): void {
if (!this._bufferService || !this._renderService) {
public refresh(shouldRecreate?: boolean): void {
if (!this._renderService) {
return;
}
for (const decoration of this._decorations) {
decoration.render(this._renderService, recreate);
decoration.render(this._renderService, shouldRecreate);
}
}

public dispose(): void {
for (const decoration of this._decorations) {
decoration.dispose();
}
if (this._container) {
this._screenElement?.removeChild(this._container);
if (this._screenElement && this._container && this._screenElement.contains(this._container)) {
this._screenElement.removeChild(this._container);
}
}
}
export class Decoration extends Disposable implements IDecoration {
private static _nextId = 1;
private readonly _marker: IMarker;
private _element: HTMLElement | undefined;
private readonly _id: number = Decoration._nextId++;

public isDisposed: boolean = false;

public get element(): HTMLElement | undefined { return this._element; }
@@ -90,48 +84,56 @@ export class Decoration extends Disposable implements IDecoration {
super();
this.x = options.x ?? 0;
this._marker = options.marker;
this._marker.onDispose(() => this.dispose());
this.anchor = options.anchor || 'left';
this.width = options.width || 1;
this.height = options.height || 1;
}

public render(renderService: IRenderService, recreate?: boolean): void {
if (!this._element || recreate) {
this._createElement(renderService, recreate);
public render(renderService: IRenderService, shouldRecreate?: boolean): void {
if (!this._element || shouldRecreate) {
this._createElement(renderService, shouldRecreate);
}
if (this._container && this._element && !this._container.contains(this._element)) {
this._container.append(this._element);
}
this._refreshStyle(renderService);
this._onRender.fire(this._element!);
if (this._element) {
this._onRender.fire(this._element);
}
}

private _createElement(renderService: IRenderService, recreate?: boolean): void {
if (recreate && this._element) {
private _createElement(renderService: IRenderService, shouldRecreate?: boolean): void {
if (shouldRecreate && this._element && this._container.contains(this._element)) {
this._container.removeChild(this._element);
}
this._element = document.createElement('div');
this._element.classList.add('xterm-decoration');
this._element.style.width = `${this.width * renderService.dimensions.scaledCellWidth}px`;
this._element.style.height = `${this.height * renderService.dimensions.scaledCellHeight}px`;
this._element.style.top = `${(this.marker.line - this._bufferService.buffers.active.ydisp) * renderService.dimensions.scaledCellHeight}px`;
this._element.style.width = `${this.width * renderService.dimensions.actualCellWidth}px`;
this._element.style.height = `${this.height * renderService.dimensions.actualCellHeight}px`;
this._element.style.top = `${(this.marker.line - this._bufferService.buffers.active.ydisp) * renderService.dimensions.actualCellHeight}px`;

if (this.x && this.x > this._bufferService.cols) {
this._element!.style.display = 'none';
// exceeded the container width, so hide
this._element.style.display = 'none';
}
if (this.anchor === 'right') {
this._element.style.right = this.x ? `${this.x * renderService.dimensions.scaledCellWidth}px` : '';
this._element.style.right = this.x ? `${this.x * renderService.dimensions.actualCellWidth}px` : '';
} else {
this._element.style.left = this.x ? `${this.x * renderService.dimensions.scaledCellWidth}px` : '';
this._element.style.left = this.x ? `${this.x * renderService.dimensions.actualCellWidth}px` : '';
}
this.register({
dispose: () => {
if (this.isDisposed) {
return;
}
this._container.removeChild(this._element!);
if (!this.marker.isDisposed) {
this.marker.dispose();
}
if (this._element && this._container.contains(this._element)) {
this._container.removeChild(this._element);
}
this.isDisposed = true;
this._marker.dispose();
// Emit before super.dispose such that dispose listeners get a change to react
this._onDispose.fire();
super.dispose();
@@ -140,13 +142,16 @@ export class Decoration extends Disposable implements IDecoration {
}

private _refreshStyle(renderService: IRenderService): void {
if (!this._element) {
return;
}
const line = this.marker.line - this._bufferService.buffers.active.ydisp;
if (line < 0 || line > this._bufferService.rows) {
// outside of viewport
this._element!.style.display = 'none';
this._element.style.display = 'none';
} else {
this._element!.style.top = `${line * renderService.dimensions.scaledCellHeight}px`;
this._element!.style.display = 'block';
this._element.style.top = `${line * renderService.dimensions.actualCellHeight}px`;
this._element.style.display = this._bufferService.buffer === this._bufferService.buffers.alt ? 'none' : 'block';
}
}
}
@@ -1232,6 +1232,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
line.fill(this._activeBuffer.getNullCell(this._eraseAttrData()));
line.isWrapped = false;
this._bufferService.buffer.clearMarkers(y);
}

/**
@@ -585,12 +585,19 @@ export class Buffer implements IBuffer {
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
}

public clearMarkers(): void {
public clearMarkers(y?: number): void {
this._isClearing = true;
for (const marker of this.markers) {
marker.dispose();
if (y) {
for (const marker of this.markers.filter(m => m.line === y)) {
marker.dispose();
this.markers.splice(this.markers.indexOf(marker), 1);
}
} else {
for (const marker of this.markers) {
marker.dispose();
}
this.markers = [];
}
this.markers = [];
this._isClearing = false;
}

@@ -45,7 +45,7 @@ export interface IBuffer {
getNullCell(attr?: IAttributeData): ICellData;
getWhitespaceCell(attr?: IAttributeData): ICellData;
addMarker(y: number): IMarker;
clearMarkers(): void;
clearMarkers(y?: number): void;
}

export interface IBufferSet extends IDisposable {

0 comments on commit 365a079

Please sign in to comment.