Replace EventEmitter usage in CharMeasure

This commit is contained in:
Daniel Imms
2019-04-02 11:38:55 -07:00
parent 60c2b20d68
commit 60113fa155
4 changed files with 11 additions and 5 deletions
+6 -4
View File
@@ -4,22 +4,24 @@
*/
import { ICharMeasure, ITerminalOptions } from '../Types';
import { EventEmitter } from '../common/EventEmitter';
import { EventEmitter2, IEvent } from '../../lib/common/EventEmitter2';
/**
* Utility class that measures the size of a character. Measurements are done in
* the DOM rather than with a canvas context because support for extracting the
* height of characters is patchy across browsers.
*/
export class CharMeasure extends EventEmitter implements ICharMeasure {
export class CharMeasure implements ICharMeasure {
private _document: Document;
private _parentElement: HTMLElement;
private _measureElement: HTMLElement;
private _width: number;
private _height: number;
private _onCharSizeChanged = new EventEmitter2<void>();
public get onCharSizeChanged(): IEvent<void> { return this._onCharSizeChanged.event; }
constructor(document: Document, parentElement: HTMLElement) {
super();
this._document = document;
this._parentElement = parentElement;
this._measureElement = this._document.createElement('span');
@@ -50,7 +52,7 @@ export class CharMeasure extends EventEmitter implements ICharMeasure {
if (this._width !== geometry.width || this._height !== adjustedHeight) {
this._width = geometry.width;
this._height = adjustedHeight;
this.emit('charsizechanged');
this._onCharSizeChanged.fire();
}
}
}
+1
View File
@@ -174,6 +174,7 @@ export class MockTerminal implements ITerminal {
}
export class MockCharMeasure implements ICharMeasure {
onCharSizeChanged: IEvent<void>;
width: number;
height: number;
measure(options: ITerminalOptions): void {