From 9a394de681ad0a1f90a9c86bf3a77b88a304c580 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 7 Feb 2017 11:38:37 -0500 Subject: [PATCH] Fixes #26 line annotation is wrong after delete https://github.com/eamodio/vscode-gitlens/issues/26 --- src/blameStatusBarController.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/blameStatusBarController.ts b/src/blameStatusBarController.ts index 2ba9b0f..6e012f6 100644 --- a/src/blameStatusBarController.ts +++ b/src/blameStatusBarController.ts @@ -1,8 +1,8 @@ 'use strict'; import { Objects } from './system'; -import { DecorationOptions, DecorationInstanceRenderOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextEditorDecorationType, TextEditor, TextEditorSelectionChangeEvent, window, workspace } from 'vscode'; +import { DecorationOptions, DecorationInstanceRenderOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextDocumentChangeEvent, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode'; import BlameAnnotationFormatter, { BlameAnnotationFormat } from './blameAnnotationFormatter'; -import { TextEditorComparer } from './comparers'; +import { TextDocumentComparer, TextEditorComparer } from './comparers'; import { IBlameConfig, IConfig, StatusBarCommand } from './configuration'; import { DocumentSchemes } from './constants'; import GitProvider, { GitCommit, GitUri, IGitBlame, IGitCommitLine } from './gitProvider'; @@ -87,7 +87,8 @@ export default class BlameStatusBarController extends Disposable { const subscriptions: Disposable[] = []; subscriptions.push(window.onDidChangeActiveTextEditor(this._onActiveTextEditorChanged, this)); - subscriptions.push(window.onDidChangeTextEditorSelection(this._onActiveSelectionChanged, this)); + subscriptions.push(window.onDidChangeTextEditorSelection(this._onEditorSelectionChanged, this)); + subscriptions.push(workspace.onDidChangeTextDocument(this._onDocumentChanged, this)); this._activeEditorLineDisposable = Disposable.from(...subscriptions); } @@ -132,12 +133,20 @@ export default class BlameStatusBarController extends Disposable { return await this._showBlame(e.selection.active.line, e); } - private async _onActiveSelectionChanged(e: TextEditorSelectionChangeEvent): Promise { + private async _onEditorSelectionChanged(e: TextEditorSelectionChangeEvent): Promise { + // Make sure this is for the editor we are tracking if (!TextEditorComparer.equals(e.textEditor, this._editor)) return; return await this._showBlame(e.selections[0].active.line, e.textEditor); } + private async _onDocumentChanged(e: TextDocumentChangeEvent): Promise { + // Make sure this is for the editor we are tracking + if (!this._editor || !TextDocumentComparer.equals(e.document, this._editor.document)) return; + + return await this._showBlame(this._editor.selections[0].active.line, this._editor); + } + private async _showBlame(line: number, editor: TextEditor) { line = line - this._uri.offset;