From 15c81ef36f6698a7f1b2505d117aa5c7c26f3c11 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 5 Feb 2017 15:44:30 -0500 Subject: [PATCH] Adds advanced setting for toggling whitespace This is in-case it is still needed (it if off by default) --- package.json | 5 +++++ src/blameAnnotationController.ts | 21 ++++++++++++++++++++- src/configuration.ts | 3 +++ src/whitespaceController.ts | 13 +++++++++++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 47d44d4..c34d449 100644 --- a/package.json +++ b/package.json @@ -245,6 +245,11 @@ "verbose" ], "description": "Specifies how much (if any) output will be sent to the GitLens output channel" + }, + "gitlens.advanced.toggleWhitespace.enabled": { + "type": "boolean", + "default": false, + "description": "Specifies whether or not to toggle whitespace off then showing blame annotations (*may* be required by certain fonts/themes)" } } }, diff --git a/src/blameAnnotationController.ts b/src/blameAnnotationController.ts index 318cbb6..35fca8e 100644 --- a/src/blameAnnotationController.ts +++ b/src/blameAnnotationController.ts @@ -3,6 +3,7 @@ import { Functions } from './system'; import { Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode'; import { BlameAnnotationProvider } from './blameAnnotationProvider'; import { TextDocumentComparer, TextEditorComparer } from './comparers'; +// import { IAdvancedConfig } from './configuration'; import GitProvider from './gitProvider'; import { Logger } from './logger'; import WhitespaceController from './whitespaceController'; @@ -11,12 +12,19 @@ export default class BlameAnnotationController extends Disposable { private _annotationProviders: Map = new Map(); private _blameAnnotationsDisposable: Disposable; + private _disposable: Disposable; private _whitespaceController: WhitespaceController | undefined; constructor(private context: ExtensionContext, private git: GitProvider) { super(() => this.dispose()); - this._whitespaceController = new WhitespaceController(context); + this._onConfigure(); + + const subscriptions: Disposable[] = []; + + subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this)); + + this._disposable = Disposable.from(...subscriptions); } dispose() { @@ -24,6 +32,17 @@ export default class BlameAnnotationController extends Disposable { this._blameAnnotationsDisposable && this._blameAnnotationsDisposable.dispose(); this._whitespaceController && this._whitespaceController.dispose(); + this._disposable && this._disposable.dispose(); + } + + private _onConfigure() { + const toggleWhitespace = workspace.getConfiguration('gitlens.advanced.toggleWhitespace').get('enabled'); + if (toggleWhitespace && !this._whitespaceController) { + this._whitespaceController = new WhitespaceController(); + } + else if (!toggleWhitespace && this._whitespaceController) { + this._whitespaceController.dispose(); + } } async clear(column: number) { diff --git a/src/configuration.ts b/src/configuration.ts index 8e2a60c..4430fbb 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -99,6 +99,9 @@ export interface IAdvancedConfig { output: { level: OutputLevel; }; + toggleWhitespace: { + enabled: boolean; + }; } export interface IConfig { diff --git a/src/whitespaceController.ts b/src/whitespaceController.ts index 2a9a3a2..4625af8 100644 --- a/src/whitespaceController.ts +++ b/src/whitespaceController.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Disposable, ExtensionContext, workspace } from 'vscode'; +import { Disposable, workspace } from 'vscode'; import { Logger } from './logger'; enum SettingLocation { @@ -12,12 +12,13 @@ export default class WhitespaceController extends Disposable { private _count: number = 0; private _disposable: Disposable; + private _disposed: boolean = false; private _ignoreNextConfigChange: boolean = false; private _renderWhitespace: string; private _renderWhitespaceLocation: SettingLocation = SettingLocation.default; private _requiresOverride: boolean; - constructor(context: ExtensionContext) { + constructor() { super(() => this.dispose()); const subscriptions: Disposable[] = []; @@ -30,12 +31,16 @@ export default class WhitespaceController extends Disposable { } dispose() { + this._disposed = true; if (this._count !== 0) { this._restoreWhitespace(); + this._count = 0; } } private _onConfigurationChanged() { + if (this._disposed) return; + if (this._ignoreNextConfigChange) { this._ignoreNextConfigChange = false; Logger.log(`Whitespace changed; ignored`); @@ -70,6 +75,8 @@ export default class WhitespaceController extends Disposable { } override() { + if (this._disposed) return; + Logger.log(`Request whitespace override; count=${this._count}`); if (this._count === 0 && this._requiresOverride) { this._ignoreNextConfigChange = true; @@ -86,6 +93,8 @@ export default class WhitespaceController extends Disposable { } restore() { + if (this._disposed) return; + Logger.log(`Request whitespace restore; count=${this._count}`); this._count--; if (this._count === 0 && this._requiresOverride) {