Move over to vs disposables

This commit is contained in:
Daniel Imms
2024-07-14 16:19:20 -07:00
parent aee936264b
commit 144bdb5dd0
43 changed files with 349 additions and 470 deletions
+5 -5
View File
@@ -5,7 +5,7 @@
import { IOptionsService } from 'common/services/Services';
import { ICharSizeService } from 'browser/services/Services';
import { Disposable } from 'common/Lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { Emitter } from 'vs/base/common/event';
export class CharSizeService extends Disposable implements ICharSizeService {
@@ -17,7 +17,7 @@ export class CharSizeService extends Disposable implements ICharSizeService {
public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
private readonly _onCharSizeChange = this.register(new Emitter<void>());
private readonly _onCharSizeChange = this._register(new Emitter<void>());
public readonly onCharSizeChange = this._onCharSizeChange.event;
constructor(
@@ -27,11 +27,11 @@ export class CharSizeService extends Disposable implements ICharSizeService {
) {
super();
try {
this._measureStrategy = this.register(new TextMetricsMeasureStrategy(this._optionsService));
this._measureStrategy = this._register(new TextMetricsMeasureStrategy(this._optionsService));
} catch {
this._measureStrategy = this.register(new DomMeasureStrategy(document, parentElement, this._optionsService));
this._measureStrategy = this._register(new DomMeasureStrategy(document, parentElement, this._optionsService));
}
this.register(this._optionsService.onMultipleOptionChange(['fontFamily', 'fontSize'], () => this.measure()));
this._register(this._optionsService.onMultipleOptionChange(['fontFamily', 'fontSize'], () => this.measure()));
}
public measure(): void {
+12 -13
View File
@@ -3,22 +3,21 @@
* @license MIT
*/
import { Disposable, toDisposable } from 'common/Lifecycle';
import { ICoreBrowserService } from './Services';
import { Emitter, Event } from 'vs/base/common/event';
import { addDisposableListener } from 'vs/base/browser/dom';
import { MutableDisposable } from 'vs/base/common/lifecycle';
import { Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
export class CoreBrowserService extends Disposable implements ICoreBrowserService {
public serviceBrand: undefined;
private _isFocused = false;
private _cachedIsFocused: boolean | undefined = undefined;
private _screenDprMonitor = this.register(new ScreenDprMonitor(this._window));
private _screenDprMonitor = this._register(new ScreenDprMonitor(this._window));
private readonly _onDprChange = this.register(new Emitter<number>());
private readonly _onDprChange = this._register(new Emitter<number>());
public readonly onDprChange = this._onDprChange.event;
private readonly _onWindowChange = this.register(new Emitter<Window & typeof globalThis>());
private readonly _onWindowChange = this._register(new Emitter<Window & typeof globalThis>());
public readonly onWindowChange = this._onWindowChange.event;
constructor(
@@ -29,11 +28,11 @@ export class CoreBrowserService extends Disposable implements ICoreBrowserServic
super();
// Monitor device pixel ratio
this.register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w)));
this.register(Event.forward(this._screenDprMonitor.onDprChange, this._onDprChange));
this._register(this.onWindowChange(w => this._screenDprMonitor.setWindow(w)));
this._register(Event.forward(this._screenDprMonitor.onDprChange, this._onDprChange));
this.register(addDisposableListener(this._textarea, 'focus', () => this._isFocused = true));
this.register(addDisposableListener(this._textarea, 'blur', () => this._isFocused = false));
this._register(addDisposableListener(this._textarea, 'focus', () => this._isFocused = true));
this._register(addDisposableListener(this._textarea, 'blur', () => this._isFocused = false));
}
public get window(): Window & typeof globalThis {
@@ -66,7 +65,7 @@ export class CoreBrowserService extends Disposable implements ICoreBrowserServic
* window.devicePixelRatio value changes. This is done not with polling but with
* the use of window.matchMedia to watch media queries. When the event fires,
* the listener will be reattached using a different media query to ensure that
* any further changes will register.
* any further changes will _register.
*
* The listener should fire on both window zoom changes and switching to a
* monitor with a different DPI.
@@ -75,9 +74,9 @@ class ScreenDprMonitor extends Disposable {
private _currentDevicePixelRatio: number;
private _outerListener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | undefined;
private _resolutionMediaMatchList: MediaQueryList | undefined;
private _windowResizeListener = this.register(new MutableDisposable());
private _windowResizeListener = this._register(new MutableDisposable());
private readonly _onDprChange = this.register(new Emitter<number>());
private readonly _onDprChange = this._register(new Emitter<number>());
public readonly onDprChange = this._onDprChange.event;
constructor(private _parentWindow: Window) {
@@ -92,7 +91,7 @@ class ScreenDprMonitor extends Disposable {
this._setWindowResizeListener();
// Setup additional disposables
this.register(toDisposable(() => this.clearListener()));
this._register(toDisposable(() => this.clearListener()));
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { ILinkProvider, ILinkProviderService } from 'browser/services/Services';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IDisposable } from 'common/Types';
export class LinkProviderService extends Disposable implements ILinkProviderService {
@@ -9,7 +9,7 @@ export class LinkProviderService extends Disposable implements ILinkProviderServ
constructor() {
super();
this.register(toDisposable(() => this.linkProviders.length = 0));
this._register(toDisposable(() => this.linkProviders.length = 0));
}
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
+19 -19
View File
@@ -7,7 +7,7 @@ import { RenderDebouncer } from 'browser/RenderDebouncer';
import { IRenderDebouncerWithCallback } from 'browser/Types';
import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types';
import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { DebouncedIdleTask } from 'common/TaskQueue';
import { IBufferService, IDecorationService, IOptionsService } from 'common/services/Services';
import { Emitter } from 'vs/base/common/event';
@@ -22,10 +22,10 @@ interface ISelectionState {
export class RenderService extends Disposable implements IRenderService {
public serviceBrand: undefined;
private _renderer: MutableDisposable<IRenderer> = this.register(new MutableDisposable());
private _renderer: MutableDisposable<IRenderer> = this._register(new MutableDisposable());
private _renderDebouncer: IRenderDebouncerWithCallback;
private _pausedResizeTask = new DebouncedIdleTask();
private _observerDisposable = this.register(new MutableDisposable());
private _observerDisposable = this._register(new MutableDisposable());
private _isPaused: boolean = false;
private _needsFullRefresh: boolean = false;
@@ -39,13 +39,13 @@ export class RenderService extends Disposable implements IRenderService {
columnSelectMode: false
};
private readonly _onDimensionsChange = this.register(new Emitter<IRenderDimensions>());
private readonly _onDimensionsChange = this._register(new Emitter<IRenderDimensions>());
public readonly onDimensionsChange = this._onDimensionsChange.event;
private readonly _onRenderedViewportChange = this.register(new Emitter<{ start: number, end: number }>());
private readonly _onRenderedViewportChange = this._register(new Emitter<{ start: number, end: number }>());
public readonly onRenderedViewportChange = this._onRenderedViewportChange.event;
private readonly _onRender = this.register(new Emitter<{ start: number, end: number }>());
private readonly _onRender = this._register(new Emitter<{ start: number, end: number }>());
public readonly onRender = this._onRender.event;
private readonly _onRefreshRequest = this.register(new Emitter<{ start: number, end: number }>());
private readonly _onRefreshRequest = this._register(new Emitter<{ start: number, end: number }>());
public readonly onRefreshRequest = this._onRefreshRequest.event;
public get dimensions(): IRenderDimensions { return this._renderer.value!.dimensions; }
@@ -63,23 +63,23 @@ export class RenderService extends Disposable implements IRenderService {
super();
this._renderDebouncer = new RenderDebouncer((start, end) => this._renderRows(start, end), coreBrowserService);
this.register(this._renderDebouncer);
this._register(this._renderDebouncer);
this.register(coreBrowserService.onDprChange(() => this.handleDevicePixelRatioChange()));
this._register(coreBrowserService.onDprChange(() => this.handleDevicePixelRatioChange()));
this.register(bufferService.onResize(() => this._fullRefresh()));
this.register(bufferService.buffers.onBufferActivate(() => this._renderer.value?.clear()));
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
this.register(this._charSizeService.onCharSizeChange(() => this.handleCharSizeChanged()));
this._register(bufferService.onResize(() => this._fullRefresh()));
this._register(bufferService.buffers.onBufferActivate(() => this._renderer.value?.clear()));
this._register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
this._register(this._charSizeService.onCharSizeChange(() => this.handleCharSizeChanged()));
// Do a full refresh whenever any decoration is added or removed. This may not actually result
// in changes but since decorations should be used sparingly or added/removed all in the same
// frame this should have minimal performance impact.
this.register(decorationService.onDecorationRegistered(() => this._fullRefresh()));
this.register(decorationService.onDecorationRemoved(() => this._fullRefresh()));
this._register(decorationService.onDecorationRegistered(() => this._fullRefresh()));
this._register(decorationService.onDecorationRemoved(() => this._fullRefresh()));
// Clear the renderer when the a change that could affect glyphs occurs
this.register(optionsService.onMultipleOptionChange([
this._register(optionsService.onMultipleOptionChange([
'customGlyphs',
'drawBoldTextInBrightColors',
'letterSpacing',
@@ -97,15 +97,15 @@ export class RenderService extends Disposable implements IRenderService {
}));
// Refresh the cursor line when the cursor changes
this.register(optionsService.onMultipleOptionChange([
this._register(optionsService.onMultipleOptionChange([
'cursorBlink',
'cursorStyle'
], () => this.refreshRows(bufferService.buffer.y, bufferService.buffer.y, true)));
this.register(themeService.onChangeColors(() => this._fullRefresh()));
this._register(themeService.onChangeColors(() => this._fullRefresh()));
this._registerIntersectionObserver(coreBrowserService.window, screenElement);
this.register(coreBrowserService.onWindowChange((w) => this._registerIntersectionObserver(w, screenElement)));
this._register(coreBrowserService.onWindowChange((w) => this._registerIntersectionObserver(w, screenElement)));
}
private _registerIntersectionObserver(w: Window & typeof globalThis, screenElement: HTMLElement): void {
+7 -7
View File
@@ -9,7 +9,7 @@ import { moveToCellSequence } from 'browser/input/MoveToCell';
import { SelectionModel } from 'browser/selection/SelectionModel';
import { ISelectionRedrawRequestEvent, ISelectionRequestScrollLinesEvent } from 'browser/selection/Types';
import { ICoreBrowserService, IMouseService, IRenderService, ISelectionService } from 'browser/services/Services';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import * as Browser from 'common/Platform';
import { IBufferLine, IDisposable } from 'common/Types';
import { getRangeLength } from 'common/buffer/BufferRange';
@@ -111,13 +111,13 @@ 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 Emitter<string>());
private readonly _onLinuxMouseSelection = this._register(new Emitter<string>());
public readonly onLinuxMouseSelection = this._onLinuxMouseSelection.event;
private readonly _onRedrawRequest = this.register(new Emitter<ISelectionRedrawRequestEvent>());
private readonly _onRedrawRequest = this._register(new Emitter<ISelectionRedrawRequestEvent>());
public readonly onRequestRedraw = this._onRedrawRequest.event;
private readonly _onSelectionChange = this.register(new Emitter<void>());
private readonly _onSelectionChange = this._register(new Emitter<void>());
public readonly onSelectionChange = this._onSelectionChange.event;
private readonly _onRequestScrollLines = this.register(new Emitter<ISelectionRequestScrollLinesEvent>());
private readonly _onRequestScrollLines = this._register(new Emitter<ISelectionRequestScrollLinesEvent>());
public readonly onRequestScrollLines = this._onRequestScrollLines.event;
constructor(
@@ -142,14 +142,14 @@ export class SelectionService extends Disposable implements ISelectionService {
}
});
this._trimListener = this._bufferService.buffer.lines.onTrim(amount => this._handleTrim(amount));
this.register(this._bufferService.buffers.onBufferActivate(e => this._handleBufferActivate(e)));
this._register(this._bufferService.buffers.onBufferActivate(e => this._handleBufferActivate(e)));
this.enable();
this._model = new SelectionModel(this._bufferService);
this._activeSelectionMode = SelectionMode.NORMAL;
this.register(toDisposable(() => {
this._register(toDisposable(() => {
this._removeMouseDownListeners();
}));
}
+4 -4
View File
@@ -7,7 +7,7 @@ import { ColorContrastCache } from 'browser/ColorContrastCache';
import { IThemeService } from 'browser/services/Services';
import { DEFAULT_ANSI_COLORS, IColorContrastCache, IColorSet, ReadonlyColorSet } from 'browser/Types';
import { color, css, NULL_COLOR } from 'common/Color';
import { Disposable } from 'common/Lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { IOptionsService, ITheme } from 'common/services/Services';
import { AllColorIndex, IColor, SpecialColorIndex } from 'common/Types';
import { Emitter } from 'vs/base/common/event';
@@ -40,7 +40,7 @@ export class ThemeService extends Disposable implements IThemeService {
public get colors(): ReadonlyColorSet { return this._colors; }
private readonly _onChangeColors = this.register(new Emitter<ReadonlyColorSet>());
private readonly _onChangeColors = this._register(new Emitter<ReadonlyColorSet>());
public readonly onChangeColors = this._onChangeColors.event;
constructor(
@@ -69,8 +69,8 @@ export class ThemeService extends Disposable implements IThemeService {
this._updateRestoreColors();
this._setTheme(this._optionsService.rawOptions.theme);
this.register(this._optionsService.onSpecificOptionChange('minimumContrastRatio', () => this._contrastCache.clear()));
this.register(this._optionsService.onSpecificOptionChange('theme', () => this._setTheme(this._optionsService.rawOptions.theme)));
this._register(this._optionsService.onSpecificOptionChange('minimumContrastRatio', () => this._contrastCache.clear()));
this._register(this._optionsService.onSpecificOptionChange('theme', () => this._setTheme(this._optionsService.rawOptions.theme)));
}
/**