Remove Events.ts in favor of new Event.forward

This commit is contained in:
Daniel Imms
2024-07-14 08:50:37 -07:00
parent 460a1370d7
commit ae8f2dd61a
10 changed files with 33 additions and 53 deletions
+5 -6
View File
@@ -44,7 +44,6 @@ import { ICharSizeService, ICharacterJoinerService, ICoreBrowserService, ILinkPr
import { ThemeService } from 'browser/services/ThemeService';
import { channels, color } from 'common/Color';
import { CoreTerminal } from 'common/CoreTerminal';
import { forwardEvent } from 'common/Events';
import { MutableDisposable, toDisposable } from 'common/Lifecycle';
import * as Browser from 'common/Platform';
import { ColorRequestType, CoreMouseAction, CoreMouseButton, CoreMouseEventType, IColorEvent, ITerminalOptions, KeyboardResultType, SpecialColorIndex } from 'common/Types';
@@ -58,7 +57,7 @@ import { IDecorationService } from 'common/services/Services';
import { WindowsOptionsReportType } from '../common/InputHandler';
import { AccessibilityManager } from './AccessibilityManager';
import { Linkifier } from './Linkifier';
import { Emitter, type Event } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
public textarea: HTMLTextAreaElement | undefined;
@@ -166,10 +165,10 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
this.register(this._inputHandler.onRequestReset(() => this.reset()));
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
this.register(this._inputHandler.onColor((event) => this._handleColorEvent(event)));
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
this.register(Event.forward(this._inputHandler.onCursorMove, this._onCursorMove));
this.register(Event.forward(this._inputHandler.onTitleChange, this._onTitleChange));
this.register(Event.forward(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
this.register(Event.forward(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
// Setup listeners
this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
+2 -3
View File
@@ -5,9 +5,8 @@
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
import { ICoreBrowserService } from './Services';
import { forwardEvent } from 'common/Events';
import { addDisposableDomListener } from 'browser/Lifecycle';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
export class CoreBrowserService extends Disposable implements ICoreBrowserService {
public serviceBrand: undefined;
@@ -30,7 +29,7 @@ export class CoreBrowserService extends Disposable implements ICoreBrowserServic
// Monitor device pixel ratio
this.register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w)));
this.register(forwardEvent(this._screenDprMonitor.onDprChange, this._onDprChange));
this.register(Event.forward(this._screenDprMonitor.onDprChange, this._onDprChange));
this.register(
addDisposableDomListener(this._textarea, 'focus', () => (this._isFocused = true))
+6 -7
View File
@@ -29,7 +29,6 @@ import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/Buffe
import { OptionsService } from 'common/services/OptionsService';
import { IDisposable, IAttributeData, ICoreTerminal, IScrollEvent } from 'common/Types';
import { CoreService } from 'common/services/CoreService';
import { forwardEvent } from 'common/Events';
import { CoreMouseService } from 'common/services/CoreMouseService';
import { UnicodeService } from 'common/services/UnicodeService';
import { CharsetService } from 'common/services/CharsetService';
@@ -39,7 +38,7 @@ import { IBufferSet } from 'common/buffer/Types';
import { InputHandler } from 'common/InputHandler';
import { WriteBuffer } from 'common/input/WriteBuffer';
import { OscLinkService } from 'common/services/OscLinkService';
import { Emitter, type Event } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
// Only trigger this warning a single time per session
let hasWriteSyncWarnHappened = false;
@@ -124,13 +123,13 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
// Register input handler and handle/forward events
this._inputHandler = this.register(new InputHandler(this._bufferService, this._charsetService, this.coreService, this._logService, this.optionsService, this._oscLinkService, this.coreMouseService, this.unicodeService));
this.register(forwardEvent(this._inputHandler.onLineFeed, this._onLineFeed));
this.register(Event.forward(this._inputHandler.onLineFeed, this._onLineFeed));
this.register(this._inputHandler);
// Setup listeners
this.register(forwardEvent(this._bufferService.onResize, this._onResize));
this.register(forwardEvent(this.coreService.onData, this._onData));
this.register(forwardEvent(this.coreService.onBinary, this._onBinary));
this.register(Event.forward(this._bufferService.onResize, this._onResize));
this.register(Event.forward(this.coreService.onData, this._onData));
this.register(Event.forward(this.coreService.onBinary, this._onBinary));
this.register(this.coreService.onRequestScrollToBottom(() => this.scrollToBottom(true)));
this.register(this.coreService.onUserInput(() => this._writeBuffer.handleUserInput()));
this.register(this.optionsService.onMultipleOptionChange(['windowsMode', 'windowsPty'], () => this._handleWindowsPtyOptionChange()));
@@ -140,7 +139,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
}));
// Setup WriteBuffer
this._writeBuffer = this.register(new WriteBuffer((data, promiseResult) => this._inputHandler.parse(data, promiseResult)));
this.register(forwardEvent(this._writeBuffer.onWriteParsed, this._onWriteParsed));
this.register(Event.forward(this._writeBuffer.onWriteParsed, this._onWriteParsed));
}
public write(data: string | Uint8Array, callback?: () => void): void {
-11
View File
@@ -1,11 +0,0 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { IDisposable } from 'common/Types';
import type { Emitter, Event } from 'vs/base/common/event';
export function forwardEvent<T>(from: Event<T>, to: Emitter<T>): IDisposable {
return from(e => to.fire(e));
}
+5 -6
View File
@@ -24,9 +24,8 @@
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { IBuffer } from 'common/buffer/Types';
import { CoreTerminal } from 'common/CoreTerminal';
import { forwardEvent } from 'common/Events';
import { IMarker, ITerminalOptions } from 'common/Types';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
export class Terminal extends CoreTerminal {
private readonly _onBell = this.register(new Emitter<void>());
@@ -50,10 +49,10 @@ export class Terminal extends CoreTerminal {
// Setup InputHandler listeners
this.register(this._inputHandler.onRequestBell(() => this.bell()));
this.register(this._inputHandler.onRequestReset(() => this.reset()));
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
this.register(Event.forward(this._inputHandler.onCursorMove, this._onCursorMove));
this.register(Event.forward(this._inputHandler.onTitleChange, this._onTitleChange));
this.register(Event.forward(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
this.register(Event.forward(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
}
/**