Replace EventEmitter usage in CharMeasure
This commit is contained in:
+1
-1
@@ -748,7 +748,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
// dprchange should handle this case, we need this as well for browsers that don't support the
|
||||
// matchMedia query.
|
||||
this.register(addDisposableDomListener(window, 'resize', () => this.renderer.onWindowResize(window.devicePixelRatio)));
|
||||
this.register(this.charMeasure.addDisposableListener('charsizechanged', () => this.renderer.onCharSizeChanged()));
|
||||
this.register(this.charMeasure.onCharSizeChanged(() => this.renderer.onCharSizeChanged()));
|
||||
this.register(this.renderer.addDisposableListener('resize', (dimensions) => this.viewport.syncScrollArea()));
|
||||
|
||||
this.selectionManager = new SelectionManager(this, this.charMeasure);
|
||||
|
||||
@@ -253,6 +253,9 @@ export interface IMouseHelper {
|
||||
export interface ICharMeasure {
|
||||
width: number;
|
||||
height: number;
|
||||
|
||||
onCharSizeChanged: IEvent<void>;
|
||||
|
||||
measure(options: ITerminalOptions): void;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user