Skip to content

Commit 9cc96d4

Browse files
committed
Fixes #81 - Current line annotation is too sticky
1 parent 41785f6 commit 9cc96d4

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/currentLineController.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class CurrentLineController extends Disposable {
2323
private _currentLine: number = -1;
2424
private _disposable: Disposable;
2525
private _editor: TextEditor | undefined;
26+
private _isAnnotating: boolean = false;
2627
private _statusBarItem: StatusBarItem | undefined;
2728
private _updateBlameDebounced: (line: number, editor: TextEditor) => Promise<void>;
2829
private _uri: GitUri;
@@ -44,7 +45,7 @@ export class CurrentLineController extends Disposable {
4445
}
4546

4647
dispose() {
47-
this._editor && this._editor.setDecorations(annotationDecoration, []);
48+
this._clearAnnotations(this._editor, true);
4849

4950
this._activeEditorLineDisposable && this._activeEditorLineDisposable.dispose();
5051
this._statusBarItem && this._statusBarItem.dispose();
@@ -61,9 +62,7 @@ export class CurrentLineController extends Disposable {
6162
!Objects.areEquivalent(cfg.annotations.line.hover, this._config && this._config.annotations.line.hover) ||
6263
!Objects.areEquivalent(cfg.theme.annotations.line.trailing, this._config && this._config.theme.annotations.line.trailing)) {
6364
changed = true;
64-
if (this._editor) {
65-
this._editor.setDecorations(annotationDecoration, []);
66-
}
65+
this._clearAnnotations(this._editor);
6766
}
6867

6968
if (!Objects.areEquivalent(cfg.statusBar, this._config && this._config.statusBar)) {
@@ -117,13 +116,10 @@ export class CurrentLineController extends Disposable {
117116

118117
private async _onActiveTextEditorChanged(editor: TextEditor | undefined) {
119118
this._currentLine = -1;
120-
121-
const previousEditor = this._editor;
122-
previousEditor && previousEditor.setDecorations(annotationDecoration, []);
119+
this._clearAnnotations(this._editor);
123120

124121
if (editor === undefined || !this.isEditorBlameable(editor)) {
125122
this.clear(editor);
126-
127123
this._editor = undefined;
128124

129125
return;
@@ -169,12 +165,14 @@ export class CurrentLineController extends Disposable {
169165

170166
const line = e.selections[0].active.line;
171167
if (line === this._currentLine) return;
168+
172169
this._currentLine = line;
173170

174-
if (!this._uri && e.textEditor) {
171+
if (!this._uri && e.textEditor !== undefined) {
175172
this._uri = await GitUri.fromUri(e.textEditor.document.uri, this.git);
176173
}
177174

175+
this._clearAnnotations(e.textEditor);
178176
this._updateBlameDebounced(line, e.textEditor);
179177
}
180178

@@ -198,18 +196,22 @@ export class CurrentLineController extends Disposable {
198196
}
199197
}
200198

201-
async clear(editor: TextEditor | undefined, previousEditor?: TextEditor) {
202-
this._clearAnnotations(editor, previousEditor);
199+
async clear(editor: TextEditor | undefined) {
200+
this._clearAnnotations(editor, true);
203201
this._statusBarItem && this._statusBarItem.hide();
204202
}
203+
204+
private async _clearAnnotations(editor: TextEditor | undefined, force: boolean = false) {
205+
if (editor === undefined || (!this._isAnnotating && !force)) return;
206+
207+
editor.setDecorations(annotationDecoration, []);
208+
this._isAnnotating = false;
209+
210+
if (!force) return;
205211

206-
private async _clearAnnotations(editor: TextEditor | undefined, previousEditor?: TextEditor) {
207-
editor && editor.setDecorations(annotationDecoration, []);
208212
// I have no idea why the decorators sometimes don't get removed, but if they don't try again with a tiny delay
209-
if (editor !== undefined) {
210-
await Functions.wait(1);
211-
editor.setDecorations(annotationDecoration, []);
212-
}
213+
await Functions.wait(1);
214+
editor.setDecorations(annotationDecoration, []);
213215
}
214216

215217
async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) {
@@ -388,6 +390,7 @@ export class CurrentLineController extends Disposable {
388390

389391
if (decorationOptions.length) {
390392
editor.setDecorations(annotationDecoration, decorationOptions);
393+
this._isAnnotating = true;
391394
}
392395
}
393396

0 commit comments

Comments
 (0)