mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Removes unneeded complexity w/ whitespace toggle
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Functions, IDeferred } from './system';
|
import { Functions } from './system';
|
||||||
import { Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode';
|
import { Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode';
|
||||||
import { BlameAnnotationProvider } from './blameAnnotationProvider';
|
import { BlameAnnotationProvider } from './blameAnnotationProvider';
|
||||||
import { TextDocumentComparer, TextEditorComparer } from './comparers';
|
import { TextDocumentComparer, TextEditorComparer } from './comparers';
|
||||||
@@ -11,9 +11,7 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
|
|
||||||
private _annotationProviders: Map<number, BlameAnnotationProvider> = new Map();
|
private _annotationProviders: Map<number, BlameAnnotationProvider> = new Map();
|
||||||
private _blameAnnotationsDisposable: Disposable;
|
private _blameAnnotationsDisposable: Disposable;
|
||||||
private _pendingClearAnnotations: Map<number, (() => void) & IDeferred> = new Map();
|
private _whitespaceController: WhitespaceController | undefined;
|
||||||
private _visibleColumns: Set<number>;
|
|
||||||
private _whitespaceController: WhitespaceController;
|
|
||||||
|
|
||||||
constructor(private context: ExtensionContext, private git: GitProvider) {
|
constructor(private context: ExtensionContext, private git: GitProvider) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
@@ -22,21 +20,18 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
for (const fn of this._pendingClearAnnotations.values()) {
|
|
||||||
fn.cancel();
|
|
||||||
}
|
|
||||||
this._annotationProviders.forEach(async (p, i) => await this.clear(i));
|
this._annotationProviders.forEach(async (p, i) => await this.clear(i));
|
||||||
|
|
||||||
this._blameAnnotationsDisposable && this._blameAnnotationsDisposable.dispose();
|
this._blameAnnotationsDisposable && this._blameAnnotationsDisposable.dispose();
|
||||||
this._whitespaceController && this._whitespaceController.dispose();
|
this._whitespaceController && this._whitespaceController.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
async clear(column: number, toggleRenderWhitespace: boolean = true) {
|
async clear(column: number) {
|
||||||
const provider = this._annotationProviders.get(column);
|
const provider = this._annotationProviders.get(column);
|
||||||
if (!provider) return;
|
if (!provider) return;
|
||||||
|
|
||||||
this._annotationProviders.delete(column);
|
this._annotationProviders.delete(column);
|
||||||
await provider.dispose(toggleRenderWhitespace);
|
await provider.dispose();
|
||||||
|
|
||||||
if (this._annotationProviders.size === 0) {
|
if (this._annotationProviders.size === 0) {
|
||||||
Logger.log(`Remove listener registrations for blame annotations`);
|
Logger.log(`Remove listener registrations for blame annotations`);
|
||||||
@@ -59,7 +54,7 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
if (!await provider.supportsBlame()) return false;
|
if (!await provider.supportsBlame()) return false;
|
||||||
|
|
||||||
if (currentProvider) {
|
if (currentProvider) {
|
||||||
await this.clear(currentProvider.editor.viewColumn || -1, false);
|
await this.clear(currentProvider.editor.viewColumn || -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._blameAnnotationsDisposable && this._annotationProviders.size === 0) {
|
if (!this._blameAnnotationsDisposable && this._annotationProviders.size === 0) {
|
||||||
@@ -72,8 +67,6 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
subscriptions.push(workspace.onDidCloseTextDocument(this._onTextDocumentClosed, this));
|
subscriptions.push(workspace.onDidCloseTextDocument(this._onTextDocumentClosed, this));
|
||||||
|
|
||||||
this._blameAnnotationsDisposable = Disposable.from(...subscriptions);
|
this._blameAnnotationsDisposable = Disposable.from(...subscriptions);
|
||||||
|
|
||||||
this._visibleColumns = this._getVisibleColumns(window.visibleTextEditors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._annotationProviders.set(editor.viewColumn || -1, provider);
|
this._annotationProviders.set(editor.viewColumn || -1, provider);
|
||||||
@@ -91,36 +84,16 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getVisibleColumns(editors: TextEditor[]): Set<number> {
|
|
||||||
const set: Set<number> = new Set();
|
|
||||||
for (const e of editors) {
|
|
||||||
if (e.viewColumn === undefined && !this.git.hasGitUriForFile(e)) continue;
|
|
||||||
set.add(e.viewColumn);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _onTextDocumentClosed(e: TextDocument) {
|
private _onTextDocumentClosed(e: TextDocument) {
|
||||||
for (const [key, p] of this._annotationProviders) {
|
for (const [key, p] of this._annotationProviders) {
|
||||||
if (!TextDocumentComparer.equals(p.document, e)) continue;
|
if (!TextDocumentComparer.equals(p.document, e)) continue;
|
||||||
|
|
||||||
Logger.log('TextDocumentClosed:', `Add pending clear of blame annotations for column ${key}`);
|
Logger.log('TextDocumentClosed:', `Clear blame annotations for column ${key}`);
|
||||||
|
this.clear(key);
|
||||||
// Since we don't know if a whole column is going away -- we don't know if we should reset the whitespace
|
|
||||||
// So defer until onDidChangeVisibleTextEditors fires
|
|
||||||
const fn = Functions.debounce(() => {
|
|
||||||
this._pendingClearAnnotations.delete(key);
|
|
||||||
this.clear(key);
|
|
||||||
}, 250);
|
|
||||||
this._pendingClearAnnotations.set(key, fn);
|
|
||||||
|
|
||||||
fn();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _onTextEditorViewColumnChanged(e: TextEditorViewColumnChangeEvent) {
|
private async _onTextEditorViewColumnChanged(e: TextEditorViewColumnChangeEvent) {
|
||||||
this._visibleColumns = this._getVisibleColumns(window.visibleTextEditors);
|
|
||||||
|
|
||||||
const viewColumn = e.viewColumn || -1;
|
const viewColumn = e.viewColumn || -1;
|
||||||
|
|
||||||
Logger.log('TextEditorViewColumnChanged:', `Clear blame annotations for column ${viewColumn}`);
|
Logger.log('TextEditorViewColumnChanged:', `Clear blame annotations for column ${viewColumn}`);
|
||||||
@@ -130,36 +103,18 @@ export default class BlameAnnotationController extends Disposable {
|
|||||||
if (!TextEditorComparer.equals(p.editor, e.textEditor)) continue;
|
if (!TextEditorComparer.equals(p.editor, e.textEditor)) continue;
|
||||||
|
|
||||||
Logger.log('TextEditorViewColumnChanged:', `Clear blame annotations for column ${key}`);
|
Logger.log('TextEditorViewColumnChanged:', `Clear blame annotations for column ${key}`);
|
||||||
await this.clear(key, false);
|
await this.clear(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _onVisibleTextEditorsChanged(e: TextEditor[]) {
|
private async _onVisibleTextEditorsChanged(e: TextEditor[]) {
|
||||||
if (e.every(_ => _.document.uri.scheme === 'inmemory')) return;
|
if (e.every(_ => _.document.uri.scheme === 'inmemory')) return;
|
||||||
|
|
||||||
this._visibleColumns = this._getVisibleColumns(e);
|
|
||||||
|
|
||||||
for (const [key, fn] of this._pendingClearAnnotations) {
|
|
||||||
Logger.log('VisibleTextEditorsChanged:', `Remove pending blame annotations for column ${key}`);
|
|
||||||
fn.cancel();
|
|
||||||
this._pendingClearAnnotations.delete(key);
|
|
||||||
|
|
||||||
// Clear and reset the whitespace depending on if the column went away
|
|
||||||
Logger.log('VisibleTextEditorsChanged:', `Clear blame annotations for column ${key}`);
|
|
||||||
await this.clear(key, this._visibleColumns.has(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [key, p] of this._annotationProviders) {
|
for (const [key, p] of this._annotationProviders) {
|
||||||
if (e.some(_ => TextEditorComparer.equals(p.editor, _))) continue;
|
if (e.some(_ => TextEditorComparer.equals(p.editor, _))) continue;
|
||||||
|
|
||||||
Logger.log('VisibleTextEditorsChanged:', `Clear blame annotations for column ${key}`);
|
Logger.log('VisibleTextEditorsChanged:', `Clear blame annotations for column ${key}`);
|
||||||
const editor = window.activeTextEditor;
|
this.clear(key);
|
||||||
if (editor && (editor.viewColumn || -1) !== key) {
|
|
||||||
this.clear(key, false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.clear(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,7 @@ import { Iterables } from './system';
|
|||||||
import { DecorationOptions, Disposable, ExtensionContext, OverviewRulerLane, Range, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
|
import { DecorationOptions, Disposable, ExtensionContext, OverviewRulerLane, Range, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
|
||||||
import { TextDocumentComparer } from './comparers';
|
import { TextDocumentComparer } from './comparers';
|
||||||
import { BlameAnnotationStyle, IBlameConfig } from './configuration';
|
import { BlameAnnotationStyle, IBlameConfig } from './configuration';
|
||||||
// import { BuiltInCommands } from './constants';
|
|
||||||
import GitProvider, { GitCommit, GitUri, IGitBlame } from './gitProvider';
|
import GitProvider, { GitCommit, GitUri, IGitBlame } from './gitProvider';
|
||||||
import { Logger } from './logger';
|
|
||||||
import WhitespaceController from './whitespaceController';
|
import WhitespaceController from './whitespaceController';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ export class BlameAnnotationProvider extends Disposable {
|
|||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
private _uri: GitUri;
|
private _uri: GitUri;
|
||||||
|
|
||||||
constructor(context: ExtensionContext, private git: GitProvider, private whitespaceController: WhitespaceController, public editor: TextEditor) {
|
constructor(context: ExtensionContext, private git: GitProvider, private whitespaceController: WhitespaceController | undefined, public editor: TextEditor) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
|
|
||||||
if (!highlightDecoration) {
|
if (!highlightDecoration) {
|
||||||
@@ -61,17 +59,14 @@ export class BlameAnnotationProvider extends Disposable {
|
|||||||
this._disposable = Disposable.from(...subscriptions);
|
this._disposable = Disposable.from(...subscriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async dispose(toggleRenderWhitespace: boolean = true) {
|
async dispose() {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
this.editor.setDecorations(blameDecoration, []);
|
this.editor.setDecorations(blameDecoration, []);
|
||||||
this.editor.setDecorations(highlightDecoration, []);
|
this.editor.setDecorations(highlightDecoration, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Until https://github.com/Microsoft/vscode/issues/11485 is fixed -- toggle whitespace back on
|
// HACK: Until https://github.com/Microsoft/vscode/issues/11485 is fixed -- restore whitespace
|
||||||
if (toggleRenderWhitespace) {
|
this.whitespaceController && await this.whitespaceController.restore();
|
||||||
Logger.log('BlameAnnotationProvider.dispose:', `Toggle whitespace rendering on`);
|
|
||||||
await this.whitespaceController.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
@@ -91,9 +86,8 @@ export class BlameAnnotationProvider extends Disposable {
|
|||||||
const blame = await this._blame;
|
const blame = await this._blame;
|
||||||
if (!blame || !blame.lines.length) return false;
|
if (!blame || !blame.lines.length) return false;
|
||||||
|
|
||||||
// HACK: Until https://github.com/Microsoft/vscode/issues/11485 is fixed -- toggle whitespace off
|
// HACK: Until https://github.com/Microsoft/vscode/issues/11485 is fixed -- override whitespace (turn off)
|
||||||
Logger.log('BlameAnnotationProvider.provideBlameAnnotation:', `Toggle whitespace rendering off`);
|
this.whitespaceController && await this.whitespaceController.override();
|
||||||
await this.whitespaceController.override();
|
|
||||||
|
|
||||||
let blameDecorationOptions: DecorationOptions[] | undefined;
|
let blameDecorationOptions: DecorationOptions[] | undefined;
|
||||||
switch (this._config.annotation.style) {
|
switch (this._config.annotation.style) {
|
||||||
@@ -183,13 +177,13 @@ export class BlameAnnotationProvider extends Disposable {
|
|||||||
gutter = commit.sha.substring(0, 8);
|
gutter = commit.sha.substring(0, 8);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
gutter = `\\00a6\\00a0 ${this._getAuthor(commit, 17, true)}`;
|
gutter = `\\02759\\00a0 ${this._getAuthor(commit, 17, true)}`;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
gutter = `\\00a6\\00a0 ${this._getDate(commit, true)}`;
|
gutter = `\\02759\\00a0 ${this._getDate(commit, true)}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gutter = '\\00a6\\00a0';
|
gutter = '\\02759';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user