Skip to content

Commit 53e7cc0

Browse files
committed
Fixes #3914 clears annotations on split editors
1 parent 6f44a4e commit 53e7cc0

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313

1414
### Fixed
1515

16+
- Fixes [#3914](https://github.com/gitkraken/vscode-gitlens/issues/#3914) - Attempting to clear a file annotation on a split file w/o the annotation no-ops
1617
- Fixes [#3911](https://github.com/gitkraken/vscode-gitlens/issues/#3911) - Avoid Home opening when first-install isn't reliable (e.g. GitPod)
1718
- Fixes [#3888](https://github.com/gitkraken/vscode-gitlens/issues/#3888) - Graph hover should disappear when right-clicking a row
1819

src/annotations/annotationProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export interface AnnotationState {
1818
restoring?: boolean;
1919
}
2020

21-
export type TextEditorCorrelationKey = string;
21+
export type TextEditorCorrelationKey = `${string}|${number}`;
2222
export function getEditorCorrelationKey(editor: TextEditor | undefined): TextEditorCorrelationKey {
23-
return `${editor?.document.uri.toString()}|${editor?.viewColumn}`;
23+
return `${editor?.document.uri.toString()}|${editor?.viewColumn ?? 0}`;
2424
}
2525

2626
export type DidChangeStatusCallback = (e: { editor?: TextEditor; status?: AnnotationStatus }) => void;

src/annotations/fileAnnotationController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ export class FileAnnotationController implements Disposable {
273273
}
274274

275275
@log<FileAnnotationController['clear']>({ args: { 0: e => e?.document.uri.toString(true) } })
276-
clear(editor: TextEditor) {
276+
clear(editor: TextEditor | undefined) {
277277
if (this.isInWindowToggle()) return this.clearAll();
278+
if (editor == null) return;
278279

279280
return this.clearCore(getEditorCorrelationKey(editor), true);
280281
}

src/commands/toggleFileAnnotations.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Container } from '../container';
66
import { showGenericErrorMessage } from '../messages';
77
import { Logger } from '../system/logger';
88
import { command } from '../system/vscode/command';
9-
import { getEditorIfVisible, isTrackableTextEditor } from '../system/vscode/utils';
9+
import { getEditorIfVisible, getOtherVisibleTextEditors, isTrackableTextEditor } from '../system/vscode/utils';
1010
import { ActiveEditorCommand, EditorCommand } from './base';
1111

1212
@command()
@@ -17,10 +17,17 @@ export class ClearFileAnnotationsCommand extends EditorCommand {
1717

1818
async execute(editor: TextEditor | undefined, _edit: TextEditorEdit, uri?: Uri): Promise<void> {
1919
editor = getValidEditor(editor, uri);
20-
if (editor == null) return;
2120

2221
try {
23-
await this.container.fileAnnotations.clear(editor);
22+
if (!editor || this.container.fileAnnotations.isInWindowToggle()) {
23+
await this.container.fileAnnotations.clear(editor);
24+
return;
25+
}
26+
27+
// Clear split editors as though they were linked, because we can't handle the command states effectively
28+
await Promise.allSettled(
29+
[editor, ...getOtherVisibleTextEditors(editor)].map(e => this.container.fileAnnotations.clear(e)),
30+
);
2431
} catch (ex) {
2532
Logger.error(ex, 'ClearFileAnnotationsCommand');
2633
void showGenericErrorMessage('Unable to clear file annotations');
@@ -117,6 +124,35 @@ async function toggleFileAnnotations<TArgs extends ToggleFileAnnotationCommandAr
117124
},
118125
args.on,
119126
));
127+
128+
// Should we link split editors together??
129+
// if (!editor || container.fileAnnotations.isInWindowToggle()) {
130+
// void (await container.fileAnnotations.toggle(
131+
// editor,
132+
// args.type,
133+
// {
134+
// selection: args.context?.selection ?? { line: editor?.selection.active.line },
135+
// ...args.context,
136+
// },
137+
// args.on,
138+
// ));
139+
140+
// return;
141+
// }
142+
143+
// await Promise.allSettled(
144+
// [editor, ...getOtherVisibleTextEditors(editor)].map(e =>
145+
// container.fileAnnotations.toggle(
146+
// e,
147+
// args.type,
148+
// {
149+
// selection: args.context?.selection ?? { line: e?.selection.active.line },
150+
// ...args.context,
151+
// },
152+
// args.on,
153+
// ),
154+
// ),
155+
// );
120156
} catch (ex) {
121157
Logger.error(ex, 'ToggleFileAnnotationsCommand');
122158
void showGenericErrorMessage(`Unable to toggle file ${args.type} annotations`);

src/system/vscode/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export function getEditorIfVisible(documentOrUri: TextDocument | Uri): TextEdito
9898
return window.visibleTextEditors.find(e => e.document === documentOrUri);
9999
}
100100

101+
export function getOtherVisibleTextEditors(editor: TextEditor): TextEditor[] {
102+
return window.visibleTextEditors.filter(
103+
e => e !== editor && e.document.uri.toString() === editor.document.uri.toString(),
104+
);
105+
}
106+
101107
export function getQuickPickIgnoreFocusOut() {
102108
return !configuration.get('advanced.quickPick.closeOnFocusOut');
103109
}

0 commit comments

Comments
 (0)