|
1 | 1 | 'use strict'; |
2 | 2 | import { Functions } from './system'; |
3 | | -import { DecorationRenderOptions, Disposable, Event, EventEmitter, ExtensionContext, OverviewRulerLane, TextDocument, TextEditor, TextEditorDecorationType, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode'; |
| 3 | +import { DecorationRenderOptions, Disposable, Event, EventEmitter, ExtensionContext, OverviewRulerLane, TextDocument, TextDocumentChangeEvent, TextEditor, TextEditorDecorationType, TextEditorViewColumnChangeEvent, window, workspace } from 'vscode'; |
4 | 4 | import { BlameAnnotationProvider } from './blameAnnotationProvider'; |
5 | 5 | import { TextDocumentComparer, TextEditorComparer } from './comparers'; |
6 | 6 | import { IBlameConfig } from './configuration'; |
@@ -176,6 +176,7 @@ export class BlameAnnotationController extends Disposable { |
176 | 176 |
|
177 | 177 | subscriptions.push(window.onDidChangeVisibleTextEditors(Functions.debounce(this._onVisibleTextEditorsChanged, 100), this)); |
178 | 178 | subscriptions.push(window.onDidChangeTextEditorViewColumn(this._onTextEditorViewColumnChanged, this)); |
| 179 | + subscriptions.push(workspace.onDidChangeTextDocument(this._onTextDocumentChanged, this)); |
179 | 180 | subscriptions.push(workspace.onDidCloseTextDocument(this._onTextDocumentClosed, this)); |
180 | 181 | subscriptions.push(this.gitContextTracker.onDidBlameabilityChange(this._onBlameabilityChanged, this)); |
181 | 182 |
|
@@ -217,6 +218,23 @@ export class BlameAnnotationController extends Disposable { |
217 | 218 | } |
218 | 219 | } |
219 | 220 |
|
| 221 | + private _onTextDocumentChanged(e: TextDocumentChangeEvent) { |
| 222 | + for (const [key, p] of this._annotationProviders) { |
| 223 | + if (!TextDocumentComparer.equals(p.document, e.document)) continue; |
| 224 | + |
| 225 | + // We have to defer because isDirty is not reliable inside this event |
| 226 | + setTimeout(() => { |
| 227 | + // If the document is dirty all is fine, just kick out since the GitContextTracker will handle it |
| 228 | + if (e.document.isDirty) return; |
| 229 | + |
| 230 | + // If the document isn't dirty, it is very likely this event was triggered by an outside edit of this document |
| 231 | + // Which means the document has been reloaded and the blame annotations have been removed, so we need to update (clear) our state tracking |
| 232 | + Logger.log('TextDocumentChanged:', `Clear blame annotations for column ${key}`); |
| 233 | + this.clear(key); |
| 234 | + }, 1); |
| 235 | + } |
| 236 | + } |
| 237 | + |
220 | 238 | private _onTextDocumentClosed(e: TextDocument) { |
221 | 239 | for (const [key, p] of this._annotationProviders) { |
222 | 240 | if (!TextDocumentComparer.equals(p.document, e)) continue; |
|
0 commit comments