Skip to content

Commit 2ee7ae8

Browse files
authored
Git - improve enabliment of the editor decoration (microsoft#234296)
1 parent b410e9c commit 2ee7ae8

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

extensions/git/src/blame.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { DecorationOptions, l10n, Position, Range, TextEditor, TextEditorChange, TextEditorDecorationType, TextEditorChangeKind, ThemeColor, Uri, window, workspace, EventEmitter } from 'vscode';
6+
import { DecorationOptions, l10n, Position, Range, TextEditor, TextEditorChange, TextEditorDecorationType, TextEditorChangeKind, ThemeColor, Uri, window, workspace, EventEmitter, ConfigurationChangeEvent } from 'vscode';
77
import { Model } from './model';
8-
import { dispose, fromNow, IDisposable, pathEquals, runAndSubscribeEvent } from './util';
8+
import { dispose, fromNow, IDisposable, pathEquals } from './util';
99
import { Repository } from './repository';
1010
import { throttle } from './decorators';
1111
import { BlameInformation } from './git';
@@ -274,21 +274,32 @@ class GitBlameEditorDecoration {
274274
});
275275
this._disposables.push(this._decorationType);
276276

277-
this._disposables.push(runAndSubscribeEvent(workspace.onDidChangeConfiguration, e => {
278-
if (!e || e?.affectsConfiguration('git.blame.editorDecoration.enabled')) {
279-
for (const textEditor of window.visibleTextEditors) {
280-
this._updateDecorations(textEditor);
281-
}
277+
workspace.onDidChangeConfiguration(this._onDidChangeConfiguration, this, this._disposables);
278+
this._controller.onDidChangeBlameInformation(e => this._updateDecorations(e), this, this._disposables);
279+
}
280+
281+
private _onDidChangeConfiguration(e: ConfigurationChangeEvent): void {
282+
if (!e.affectsConfiguration('git.blame.editorDecoration.enabled')) {
283+
return;
284+
}
285+
286+
const enabled = this._isEnabled();
287+
for (const textEditor of window.visibleTextEditors) {
288+
if (enabled) {
289+
this._updateDecorations(textEditor);
290+
} else {
291+
textEditor.setDecorations(this._decorationType, []);
282292
}
283-
}));
293+
}
294+
}
284295

285-
this._controller.onDidChangeBlameInformation(e => this._updateDecorations(e), this, this._disposables);
296+
private _isEnabled(): boolean {
297+
const config = workspace.getConfiguration('git');
298+
return config.get<boolean>('blame.editorDecoration.enabled', false);
286299
}
287300

288301
private _updateDecorations(textEditor: TextEditor): void {
289-
const enabled = workspace.getConfiguration('git').get<boolean>('blame.editorDecoration.enabled', false);
290-
if (!enabled) {
291-
textEditor.setDecorations(this._decorationType, []);
302+
if (!this._isEnabled()) {
292303
return;
293304
}
294305

0 commit comments

Comments
 (0)