Create new event with emitter object to simplify code

This commit is contained in:
Daniel Imms
2022-10-01 08:45:40 -07:00
parent 969db2bcf9
commit ed15a8e170
33 changed files with 247 additions and 307 deletions
+12 -16
View File
@@ -9,7 +9,7 @@ import { IBufferLine, IDisposable } from 'common/Types';
import * as Browser from 'common/Platform';
import { SelectionModel } from 'browser/selection/SelectionModel';
import { CellData } from 'common/buffer/CellData';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
import { IMouseService, ISelectionService, IRenderService, ICoreBrowserService } from 'browser/services/Services';
import { IBufferRange, ILinkifier2 } from 'browser/Types';
import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services';
@@ -111,14 +111,10 @@ export class SelectionService extends Disposable implements ISelectionService {
private _oldSelectionStart: [number, number] | undefined = undefined;
private _oldSelectionEnd: [number, number] | undefined = undefined;
private readonly _onLinuxMouseSelection = this.register(new EventEmitter<string>());
public readonly onLinuxMouseSelection = this._onLinuxMouseSelection.event;
private readonly _onRedrawRequest = this.register(new EventEmitter<ISelectionRedrawRequestEvent>());
public readonly onRequestRedraw = this._onRedrawRequest.event;
private readonly _onSelectionChange = this.register(new EventEmitter<void>());
public readonly onSelectionChange = this._onSelectionChange.event;
private readonly _onRequestScrollLines = this.register(new EventEmitter<ISelectionRequestScrollLinesEvent>());
public readonly onRequestScrollLines = this._onRequestScrollLines.event;
public readonly onLinuxMouseSelection = this.register(initEvent<string>());
public readonly onRequestRedraw = this.register(initEvent<ISelectionRedrawRequestEvent>());
public readonly onSelectionChange = this.register(initEvent<void>());
public readonly onRequestScrollLines = this.register(initEvent<ISelectionRequestScrollLinesEvent>());
constructor(
private readonly _element: HTMLElement,
@@ -260,7 +256,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._model.clearSelection();
this._removeMouseDownListeners();
this.refresh();
this._onSelectionChange.fire();
this.onSelectionChange.fire();
}
/**
@@ -279,7 +275,7 @@ export class SelectionService extends Disposable implements ISelectionService {
if (Browser.isLinux && isLinuxMouseSelection) {
const selectionText = this.selectionText;
if (selectionText.length) {
this._onLinuxMouseSelection.fire(this.selectionText);
this.onLinuxMouseSelection.fire(this.selectionText);
}
}
}
@@ -290,7 +286,7 @@ export class SelectionService extends Disposable implements ISelectionService {
*/
private _refresh(): void {
this._refreshAnimationFrame = undefined;
this._onRedrawRequest.fire({
this.onRequestRedraw.fire({
start: this._model.finalSelectionStart,
end: this._model.finalSelectionEnd,
columnSelectMode: this._activeSelectionMode === SelectionMode.COLUMN
@@ -358,7 +354,7 @@ export class SelectionService extends Disposable implements ISelectionService {
public selectAll(): void {
this._model.isSelectAllActive = true;
this.refresh();
this._onSelectionChange.fire();
this.onSelectionChange.fire();
}
public selectLines(start: number, end: number): void {
@@ -368,7 +364,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._model.selectionStart = [0, start];
this._model.selectionEnd = [this._bufferService.cols, end];
this.refresh();
this._onSelectionChange.fire();
this.onSelectionChange.fire();
}
/**
@@ -665,7 +661,7 @@ export class SelectionService extends Disposable implements ISelectionService {
return;
}
if (this._dragScrollAmount) {
this._onRequestScrollLines.fire({ amount: this._dragScrollAmount, suppressScrollEvent: false });
this.onRequestScrollLines.fire({ amount: this._dragScrollAmount, suppressScrollEvent: false });
// Re-evaluate selection
// If the cursor was above or below the viewport, make sure it's at the
// start or end of the viewport respectively. This should only happen when
@@ -743,7 +739,7 @@ export class SelectionService extends Disposable implements ISelectionService {
this._oldSelectionStart = start;
this._oldSelectionEnd = end;
this._oldHasSelection = hasSelection;
this._onSelectionChange.fire();
this.onSelectionChange.fire();
}
private _onBufferActivate(e: {activeBuffer: IBuffer, inactiveBuffer: IBuffer}): void {