Skip to content

Commit 9dfce15

Browse files
committed
Adds navigation commands to Changes Annotations
- Adds "Next Change" and "Previous Change" to the editor toolbar
1 parent 6c7a604 commit 9dfce15

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

contributions.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,29 @@
372372
},
373373
"gitlens.annotations.nextChange": {
374374
"label": "Next Change",
375-
"icon": "$(arrow-down)"
375+
"icon": "$(arrow-down)",
376+
"menus": {
377+
"editor/title": [
378+
{
379+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed:changes\\b/ || (resource in gitlens:tabs:annotated:changes && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
380+
"group": "navigation",
381+
"order": -99
382+
}
383+
]
384+
}
376385
},
377386
"gitlens.annotations.previousChange": {
378387
"label": "Previous Change",
379-
"icon": "$(arrow-up)"
388+
"icon": "$(arrow-up)",
389+
"menus": {
390+
"editor/title": [
391+
{
392+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed:changes\\b/ || (resource in gitlens:tabs:annotated:changes && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
393+
"group": "navigation",
394+
"order": -100
395+
}
396+
]
397+
}
380398
},
381399
"gitlens.applyPatchFromClipboard": {
382400
"label": "Apply Copied Changes (Patch)",
@@ -449,7 +467,7 @@
449467
"menus": {
450468
"editor/title": [
451469
{
452-
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated == computed || (resource in gitlens:tabs:annotated && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
470+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed\\b/ || (resource in gitlens:tabs:annotated && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
453471
"group": "navigation",
454472
"order": 100
455473
}
@@ -582,7 +600,7 @@
582600
"menus": {
583601
"editor/title": [
584602
{
585-
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated == computing || resource in gitlens:tabs:annotated:computing) && config.gitlens.menus.editorGroup.blame",
603+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed\\b/ || resource in gitlens:tabs:annotated:computing) && config.gitlens.menus.editorGroup.blame",
586604
"group": "navigation",
587605
"order": 100
588606
}

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14476,6 +14476,16 @@
1447614476
}
1447714477
],
1447814478
"editor/title": [
14479+
{
14480+
"command": "gitlens.annotations.previousChange",
14481+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed:changes\\b/ || (resource in gitlens:tabs:annotated:changes && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
14482+
"group": "navigation@-100"
14483+
},
14484+
{
14485+
"command": "gitlens.annotations.nextChange",
14486+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed:changes\\b/ || (resource in gitlens:tabs:annotated:changes && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
14487+
"group": "navigation@-99"
14488+
},
1447914489
{
1448014490
"command": "gitlens.composer.refresh",
1448114491
"when": "activeWebviewPanelId === gitlens.composer",
@@ -14491,6 +14501,11 @@
1449114501
"when": "activeWebviewPanelId === gitlens.timeline",
1449214502
"group": "navigation@-99"
1449314503
},
14504+
{
14505+
"submenu": "gitlens/graph/configuration",
14506+
"when": "activeWebviewPanelId === gitlens.graph",
14507+
"group": "navigation@-98"
14508+
},
1449414509
{
1449514510
"command": "gitlens.graph.split",
1449614511
"when": "activeWebviewPanelId == gitlens.graph && resourceScheme == webview-panel && config.gitlens.graph.allowMultiple",
@@ -14503,12 +14518,12 @@
1450314518
},
1450414519
{
1450514520
"command": "gitlens.clearFileAnnotations",
14506-
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated == computed || (resource in gitlens:tabs:annotated && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
14521+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed\\b/ || (resource in gitlens:tabs:annotated && resource not in gitlens:tabs:annotated:computing)) && config.gitlens.menus.editorGroup.blame",
1450714522
"group": "navigation@100"
1450814523
},
1450914524
{
1451014525
"command": "gitlens.computingFileAnnotations",
14511-
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated == computing || resource in gitlens:tabs:annotated:computing) && config.gitlens.menus.editorGroup.blame",
14526+
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated =~ /computed\\b/ || resource in gitlens:tabs:annotated:computing) && config.gitlens.menus.editorGroup.blame",
1451214527
"group": "navigation@100"
1451314528
},
1451414529
{
@@ -14565,11 +14580,6 @@
1456514580
"when": "resourceScheme =~ /^(gitlens|pr)$/ && gitlens:enabled",
1456614581
"group": "navigation@-98"
1456714582
},
14568-
{
14569-
"submenu": "gitlens/graph/configuration",
14570-
"when": "activeWebviewPanelId === gitlens.graph",
14571-
"group": "navigation@-98"
14572-
},
1457314583
{
1457414584
"command": "gitlens.openRevisionFile:editor/title",
1457514585
"when": "resourceScheme =~ /^(gitlens|pr)$/ && gitlens:enabled && isInDiffEditor",

src/annotations/fileAnnotationController.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ export class FileAnnotationController implements Disposable {
334334
}
335335

336336
private readonly _annotatedUris = new UriSet();
337+
private readonly _annotatedChangesUris = new UriSet();
337338
private readonly _computingUris = new UriSet();
338339

339340
async onProviderEditorStatusChanged(
340341
editor: TextEditor | undefined,
342+
annotationType: FileAnnotationType | undefined,
341343
status: AnnotationStatus | undefined,
342344
): Promise<void> {
343345
if (editor == null) return;
@@ -346,10 +348,11 @@ export class FileAnnotationController implements Disposable {
346348
let windowStatus;
347349

348350
if (this.isInWindowToggle()) {
349-
windowStatus = status;
351+
windowStatus = status ? (annotationType ? (`${status}:${annotationType}` as const) : status) : undefined;
350352

351353
changed = Boolean(this._annotatedUris.size || this._computingUris.size);
352354
this._annotatedUris.clear();
355+
this._annotatedChangesUris.clear();
353356
this._computingUris.clear();
354357
} else {
355358
windowStatus = undefined;
@@ -373,11 +376,19 @@ export class FileAnnotationController implements Disposable {
373376
if (provider == null) {
374377
if (this._annotatedUris.has(uri)) {
375378
this._annotatedUris.delete(uri);
379+
this._annotatedChangesUris.delete(uri);
380+
changed = true;
381+
}
382+
} else {
383+
if (!this._annotatedUris.has(uri)) {
384+
this._annotatedUris.add(uri);
385+
changed = true;
386+
}
387+
388+
if (provider.annotationType === 'changes' && !this._annotatedChangesUris.has(uri)) {
389+
this._annotatedChangesUris.add(uri);
376390
changed = true;
377391
}
378-
} else if (!this._annotatedUris.has(uri)) {
379-
this._annotatedUris.add(uri);
380-
changed = true;
381392
}
382393

383394
if (this._computingUris.has(uri)) {
@@ -389,6 +400,7 @@ export class FileAnnotationController implements Disposable {
389400
default:
390401
if (this._annotatedUris.has(uri)) {
391402
this._annotatedUris.delete(uri);
403+
this._annotatedChangesUris.delete(uri);
392404
changed = true;
393405
}
394406

@@ -406,6 +418,7 @@ export class FileAnnotationController implements Disposable {
406418
setContext('gitlens:window:annotated', windowStatus),
407419
setContext('gitlens:tabs:annotated:computing', [...this._computingUris]),
408420
setContext('gitlens:tabs:annotated', [...this._annotatedUris]),
421+
setContext('gitlens:tabs:annotated:changes', [...this._annotatedChangesUris]),
409422
]);
410423
}
411424

@@ -463,12 +476,12 @@ export class FileAnnotationController implements Disposable {
463476
const provider = await window.withProgress(
464477
{ location: ProgressLocation.Window },
465478
async (progress: Progress<{ message: string }>) => {
466-
void this.onProviderEditorStatusChanged(editor, 'computing');
479+
void this.onProviderEditorStatusChanged(editor, type, 'computing');
467480

468481
const computingAnnotations = this.showAnnotationsCore(currentProvider, editor, type, context, progress);
469482
void (await computingAnnotations);
470483

471-
void this.onProviderEditorStatusChanged(editor, 'computed');
484+
void this.onProviderEditorStatusChanged(editor, type, 'computed');
472485

473486
return computingAnnotations;
474487
},
@@ -574,7 +587,7 @@ export class FileAnnotationController implements Disposable {
574587

575588
if (!this._annotationProviders.size || key === getEditorCorrelationKey(this._editor)) {
576589
if (this._editor != null) {
577-
void this.onProviderEditorStatusChanged(this._editor, undefined);
590+
void this.onProviderEditorStatusChanged(this._editor, undefined, undefined);
578591
}
579592

580593
await this.detachKeyboardHook();
@@ -636,7 +649,7 @@ export class FileAnnotationController implements Disposable {
636649
);
637650
provider = new GutterBlameAnnotationProvider(
638651
this.container,
639-
e => this.onProviderEditorStatusChanged(e.editor, e.status),
652+
e => this.onProviderEditorStatusChanged(e.editor, type, e.status),
640653
editor,
641654
trackedDocument,
642655
);
@@ -648,7 +661,7 @@ export class FileAnnotationController implements Disposable {
648661
);
649662
provider = new GutterChangesAnnotationProvider(
650663
this.container,
651-
e => this.onProviderEditorStatusChanged(e.editor, e.status),
664+
e => this.onProviderEditorStatusChanged(e.editor, type, e.status),
652665
editor,
653666
trackedDocument,
654667
);
@@ -660,7 +673,7 @@ export class FileAnnotationController implements Disposable {
660673
);
661674
provider = new GutterHeatmapBlameAnnotationProvider(
662675
this.container,
663-
e => this.onProviderEditorStatusChanged(e.editor, e.status),
676+
e => this.onProviderEditorStatusChanged(e.editor, type, e.status),
664677
editor,
665678
trackedDocument,
666679
);

src/constants.commands.generated.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type ContributedCommands =
2626
| 'gitlens.ai.rebaseOntoCommit:graph'
2727
| 'gitlens.ai.rebaseOntoCommit:views'
2828
| 'gitlens.ai.switchProvider:scm'
29+
| 'gitlens.annotations.nextChange'
30+
| 'gitlens.annotations.previousChange'
2931
| 'gitlens.changeUpstream:graph'
3032
| 'gitlens.changeUpstream:views'
3133
| 'gitlens.clearFileAnnotations'
@@ -960,7 +962,5 @@ export type ContributedKeybindingCommands =
960962
* Either their contribution point is missing or are simply internal and should be removed at some point
961963
*/
962964
export type ContributedOrphansOrInternalCommands =
963-
| 'gitlens.annotations.nextChange'
964-
| 'gitlens.annotations.previousChange'
965965
| 'gitlens.graph.pushWithForce'
966966
| 'gitlens.plus.cloudIntegrations.connect';

src/constants.context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Uri } from 'vscode';
2+
import type { FileAnnotationType } from './config';
23
import type { AnnotationStatus, Keys } from './constants';
34
import type { SubscriptionState } from './constants.subscription';
45
import type { CustomEditorTypes, GroupableTreeViewTypes, WebviewTypes, WebviewViewTypes } from './constants.views';
@@ -42,6 +43,7 @@ export type ContextKeys = {
4243
'gitlens:tabs:ai:unhelpful': Uri[];
4344
'gitlens:tabs:ai:changelog': Uri[];
4445
'gitlens:tabs:annotated': Uri[];
46+
'gitlens:tabs:annotated:changes': Uri[];
4547
'gitlens:tabs:annotated:computing': Uri[];
4648
'gitlens:tabs:blameable': Uri[];
4749
'gitlens:tabs:tracked': Uri[];
@@ -63,7 +65,7 @@ export type ContextKeys = {
6365
'gitlens:views:scm:grouped:view': GroupableTreeViewTypes;
6466
'gitlens:views:scm:grouped:welcome': boolean;
6567
'gitlens:vsls': boolean | 'host' | 'guest';
66-
'gitlens:window:annotated': AnnotationStatus;
68+
'gitlens:window:annotated': AnnotationStatus | `${AnnotationStatus}:${FileAnnotationType}`;
6769
'gitlens:walkthroughSupported': boolean;
6870
} & Record<`gitlens:action:${string}`, number> &
6971
Record<`gitlens:feature:unsupported:${Features}`, boolean> &

0 commit comments

Comments
 (0)