From 415100e8b843d748e2c117ceca4c8662eafc0041 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 9 Oct 2022 07:46:10 -0700 Subject: [PATCH] Adopt onSpecificOptionChange --- src/browser/Terminal.ts | 7 ++---- .../decorations/OverviewRulerRenderer.ts | 10 ++------- src/browser/services/ThemeService.ts | 12 ++-------- src/common/CoreTerminal.ts | 22 ++++++------------- src/common/buffer/BufferSet.ts | 3 +++ src/common/services/BufferService.ts | 2 +- src/common/services/LogService.ts | 6 +---- src/headless/Terminal.ts | 9 -------- 8 files changed, 18 insertions(+), 53 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index e0ba8a94..abb5dfdf 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -265,8 +265,6 @@ export class Terminal extends CoreTerminal implements ITerminal { } protected _updateOptions(key: string): void { - super._updateOptions(key); - // TODO: These listeners should be owned by individual components switch (key) { case 'fontFamily': @@ -307,7 +305,6 @@ export class Terminal extends CoreTerminal implements ITerminal { this._accessibilityManager = undefined; } break; - case 'tabStopWidth': this.buffers.setupTabStops(); break; } } @@ -584,8 +581,8 @@ export class Terminal extends CoreTerminal implements ITerminal { if (this.options.overviewRulerWidth) { this._overviewRulerRenderer = this.register(this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement)); } - this.optionsService.onOptionChange(() => { - if (!this._overviewRulerRenderer && this.options.overviewRulerWidth && this._viewportElement && this.screenElement) { + this.optionsService.onSpecificOptionChange('overviewRulerWidth', value => { + if (!this._overviewRulerRenderer && value && this._viewportElement && this.screenElement) { this._overviewRulerRenderer = this.register(this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement)); } }); diff --git a/src/browser/decorations/OverviewRulerRenderer.ts b/src/browser/decorations/OverviewRulerRenderer.ts index 9251d2e3..90166960 100644 --- a/src/browser/decorations/OverviewRulerRenderer.ts +++ b/src/browser/decorations/OverviewRulerRenderer.ts @@ -110,15 +110,9 @@ export class OverviewRulerRenderer extends Disposable { } })); // overview ruler width changed - this.register(this._optionsService.onOptionChange(o => { - if (o === 'overviewRulerWidth') { - this._queueRefresh(true); - } - })); + this.register(this._optionsService.onSpecificOptionChange('overviewRulerWidth', () => this._queueRefresh(true))); // device pixel ratio changed - this.register(addDisposableDomListener(this._coreBrowseService.window, 'resize', () => { - this._queueRefresh(true); - })); + this.register(addDisposableDomListener(this._coreBrowseService.window, 'resize', () => this._queueRefresh(true))); // set the canvas dimensions this._queueRefresh(true); } diff --git a/src/browser/services/ThemeService.ts b/src/browser/services/ThemeService.ts index e584a8d1..ac0104d5 100644 --- a/src/browser/services/ThemeService.ts +++ b/src/browser/services/ThemeService.ts @@ -111,16 +111,8 @@ export class ThemeService extends Disposable implements IThemeService { this._updateRestoreColors(); this._setTheme(this._optionsService.rawOptions.theme); - this.register(this._optionsService.onOptionChange(key => { - switch (key) { - case 'minimumContrastRatio': - this._contrastCache.clear(); - break; - case 'theme': - this._setTheme(this._optionsService.rawOptions.theme); - break; - } - })); + this.register(this._optionsService.onSpecificOptionChange('minimumContrastRatio', () => this._contrastCache.clear())); + this.register(this._optionsService.onSpecificOptionChange('theme', () => this._setTheme(this._optionsService.rawOptions.theme))); } /** diff --git a/src/common/CoreTerminal.ts b/src/common/CoreTerminal.ts index 5f42d8ea..8f1c2a0d 100644 --- a/src/common/CoreTerminal.ts +++ b/src/common/CoreTerminal.ts @@ -130,7 +130,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal { this.register(forwardEvent(this.coreService.onData, this._onData)); this.register(forwardEvent(this.coreService.onBinary, this._onBinary)); this.register(this.coreService.onUserInput(() => this._writeBuffer.handleUserInput())); - this.register(this.optionsService.onOptionChange(key => this._updateOptions(key))); + this.register(this.optionsService.onSpecificOptionChange('windowsMode', e => this._handleWindowsModeOptionChange(e))); this.register(this._bufferService.onScroll(event => { this._onScroll.fire({ position: this._bufferService.buffer.ydisp, source: ScrollSource.TERMINAL }); this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop, this._bufferService.buffer.scrollBottom); @@ -261,20 +261,12 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal { this.coreMouseService.reset(); } - protected _updateOptions(key: keyof ITerminalOptions): void { - // TODO: These listeners should be owned by individual components - switch (key) { - case 'scrollback': - this.buffers.resize(this.cols, this.rows); - break; - case 'windowsMode': - if (this.optionsService.rawOptions.windowsMode) { - this._enableWindowsMode(); - } else { - this._windowsMode?.dispose(); - this._windowsMode = undefined; - } - break; + private _handleWindowsModeOptionChange(value: boolean | undefined): void { + if (value) { + this._enableWindowsMode(); + } else { + this._windowsMode?.dispose(); + this._windowsMode = undefined; } } diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index 46fcb097..bc7aa58e 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -32,6 +32,8 @@ export class BufferSet extends Disposable implements IBufferSet { ) { super(); this.reset(); + this.register(this._optionsService.onSpecificOptionChange('scrollback', () => this.resize(this._bufferService.cols, this._bufferService.rows))); + this.register(this._optionsService.onSpecificOptionChange('tabStopWidth', () => this.setupTabStops())); } public reset(): void { @@ -119,6 +121,7 @@ export class BufferSet extends Disposable implements IBufferSet { public resize(newCols: number, newRows: number): void { this._normal.resize(newCols, newRows); this._alt.resize(newCols, newRows); + this.setupTabStops(newCols); } /** diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index f238206c..3f15f242 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -43,7 +43,7 @@ export class BufferService extends Disposable implements IBufferService { this.cols = cols; this.rows = rows; this.buffers.resize(cols, rows); - this.buffers.setupTabStops(this.cols); + // TODO: This doesn't fire when scrollback changes - add a resize event to BufferSet and forward event this._onResize.fire({ cols, rows }); } diff --git a/src/common/services/LogService.ts b/src/common/services/LogService.ts index 854f85de..4b56a097 100644 --- a/src/common/services/LogService.ts +++ b/src/common/services/LogService.ts @@ -40,11 +40,7 @@ export class LogService extends Disposable implements ILogService { ) { super(); this._updateLogLevel(); - this.register(this._optionsService.onOptionChange(key => { - if (key === 'logLevel') { - this._updateLogLevel(); - } - })); + this.register(this._optionsService.onSpecificOptionChange('logLevel', () => this._updateLogLevel())); } private _updateLogLevel(): void { diff --git a/src/headless/Terminal.ts b/src/headless/Terminal.ts index f021c42b..2c244f21 100644 --- a/src/headless/Terminal.ts +++ b/src/headless/Terminal.ts @@ -78,15 +78,6 @@ export class Terminal extends CoreTerminal { return this.buffers.active; } - protected _updateOptions(key: string): void { - super._updateOptions(key); - - // TODO: These listeners should be owned by individual components - switch (key) { - case 'tabStopWidth': this.buffers.setupTabStops(); break; - } - } - // TODO: Support paste here? public get markers(): IMarker[] {