-
Notifications
You must be signed in to change notification settings - Fork 30k
/
Copy pathscmViewPane.ts
3948 lines (3263 loc) · 150 KB
/
scmViewPane.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/scm';
import { Event, Emitter } from 'vs/base/common/event';
import { basename, dirname } from 'vs/base/common/resources';
import { IDisposable, Disposable, DisposableStore, combinedDisposable, dispose, toDisposable, MutableDisposable, IReference, DisposableMap } from 'vs/base/common/lifecycle';
import { ViewPane, IViewPaneOptions, ViewAction } from 'vs/workbench/browser/parts/views/viewPane';
import { append, $, Dimension, asCSSUrl, trackFocus, clearNode, prepend } from 'vs/base/browser/dom';
import { IListVirtualDelegate, IIdentityProvider } from 'vs/base/browser/ui/list/list';
import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryProviderCacheEntry, SCMHistoryItemChangeTreeElement, SCMHistoryItemGroupTreeElement, SCMHistoryItemTreeElement, SCMViewSeparatorElement } from 'vs/workbench/contrib/scm/common/history';
import { ISCMResourceGroup, ISCMResource, InputValidationType, ISCMRepository, ISCMInput, IInputValidation, ISCMViewService, ISCMViewVisibleRepositoryChangeEvent, ISCMService, SCMInputChangeReason, VIEW_PANE_ID, ISCMActionButton, ISCMActionButtonDescriptor, ISCMRepositorySortKey, ISCMInputValueProviderContext, ISCMProvider } from 'vs/workbench/contrib/scm/common/scm';
import { ResourceLabels, IResourceLabel, IFileLabelOptions } from 'vs/workbench/browser/labels';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { MenuItemAction, IMenuService, registerAction2, MenuId, IAction2Options, MenuRegistry, Action2, IMenu } from 'vs/platform/actions/common/actions';
import { IAction, ActionRunner, Action, Separator, IActionRunner } from 'vs/base/common/actions';
import { ActionBar, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
import { IThemeService, IFileIconTheme } from 'vs/platform/theme/common/themeService';
import { isSCMResource, isSCMResourceGroup, connectPrimaryMenuToInlineActionBar, isSCMRepository, isSCMInput, collectContextMenuActions, getActionViewItemProvider, isSCMActionButton, isSCMViewService, isSCMHistoryItemGroupTreeElement, isSCMHistoryItemTreeElement, isSCMHistoryItemChangeTreeElement, toDiffEditorArguments, isSCMResourceNode, isSCMHistoryItemChangeNode, isSCMViewSeparator, connectPrimaryMenu } from './util';
import { WorkbenchCompressibleAsyncDataTree, IOpenEvent } from 'vs/platform/list/browser/listService';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { disposableTimeout, Sequencer, ThrottledDelayer, Throttler } from 'vs/base/common/async';
import { ITreeNode, ITreeFilter, ITreeSorter, ITreeContextMenuEvent, ITreeDragAndDrop, ITreeDragOverReaction, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
import { ResourceTree, IResourceNode } from 'vs/base/common/resourceTree';
import { ICompressibleTreeRenderer, ICompressibleKeyboardNavigationLabelProvider } from 'vs/base/browser/ui/tree/objectTree';
import { Iterable } from 'vs/base/common/iterator';
import { ICompressedTreeNode } from 'vs/base/browser/ui/tree/compressedObjectTreeModel';
import { URI } from 'vs/base/common/uri';
import { FileKind } from 'vs/platform/files/common/files';
import { compareFileNames, comparePaths } from 'vs/base/common/comparers';
import { FuzzyScore, createMatches, IMatch } from 'vs/base/common/filters';
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
import { localize } from 'vs/nls';
import { flatten } from 'vs/base/common/arrays';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
import { SIDE_BAR_BACKGROUND, PANEL_BACKGROUND } from 'vs/workbench/common/theme';
import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditor/codeEditorWidget';
import { ITextModel } from 'vs/editor/common/model';
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
import { IModelService } from 'vs/editor/common/services/model';
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
import { EditorDictation } from 'vs/workbench/contrib/codeEditor/browser/dictation/editorDictation';
import { ContextMenuController } from 'vs/editor/contrib/contextmenu/browser/contextmenu';
import * as platform from 'vs/base/common/platform';
import { compare, format } from 'vs/base/common/strings';
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { HoverController } from 'vs/editor/contrib/hover/browser/hover';
import { ColorDetector } from 'vs/editor/contrib/colorPicker/browser/colorDetector';
import { LinkDetector } from 'vs/editor/contrib/links/browser/links';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { ILabelService } from 'vs/platform/label/common/label';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DEFAULT_FONT_FAMILY } from 'vs/base/browser/fonts';
import { Codicon } from 'vs/base/common/codicons';
import { ThemeIcon } from 'vs/base/common/themables';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
import { RepositoryActionRunner, RepositoryRenderer } from 'vs/workbench/contrib/scm/browser/scmRepositoryRenderer';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { LabelFuzzyScore } from 'vs/base/browser/ui/tree/abstractTree';
import { Selection } from 'vs/editor/common/core/selection';
import { API_OPEN_DIFF_EDITOR_COMMAND_ID, API_OPEN_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { createActionViewItem, createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { MarkdownRenderer, openLinkFromMarkdown } from 'vs/editor/browser/widget/markdownRenderer/browser/markdownRenderer';
import { Button, ButtonWithDescription, ButtonWithDropdown } from 'vs/base/browser/ui/button/button';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { RepositoryContextKeys } from 'vs/workbench/contrib/scm/browser/scmViewService';
import { DragAndDropController } from 'vs/editor/contrib/dnd/browser/dnd';
import { DropIntoEditorController } from 'vs/editor/contrib/dropOrPasteInto/browser/dropIntoEditorController';
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
import { defaultButtonStyles, defaultCountBadgeStyles } from 'vs/platform/theme/browser/defaultStyles';
import { InlineCompletionsController } from 'vs/editor/contrib/inlineCompletions/browser/inlineCompletionsController';
import { CodeActionController } from 'vs/editor/contrib/codeAction/browser/codeActionController';
import { IResolvedTextEditorModel, ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
import { Schemas } from 'vs/base/common/network';
import { IDragAndDropData } from 'vs/base/browser/dnd';
import { fillEditorsDragData } from 'vs/workbench/browser/dnd';
import { ElementsDragAndDropData, ListViewTargetSector } from 'vs/base/browser/ui/list/listView';
import { CodeDataTransfers } from 'vs/platform/dnd/browser/dnd';
import { FormatOnType } from 'vs/editor/contrib/format/browser/formatActions';
import { EditorOption, EditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IAsyncDataTreeViewState, ITreeCompressionDelegate } from 'vs/base/browser/ui/tree/asyncDataTree';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { stripIcons } from 'vs/base/common/iconLabels';
import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { foreground, listActiveSelectionForeground, registerColor, transparent } from 'vs/platform/theme/common/colorRegistry';
import { IMenuWorkbenchToolBarOptions, MenuWorkbenchToolBar, WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
import { clamp } from 'vs/base/common/numbers';
import { ILogService } from 'vs/platform/log/common/log';
// type SCMResourceTreeNode = IResourceNode<ISCMResource, ISCMResourceGroup>;
// type SCMHistoryItemChangeResourceTreeNode = IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>;
type TreeElement =
ISCMRepository |
ISCMInput |
ISCMActionButton |
ISCMResourceGroup |
ISCMResource |
IResourceNode<ISCMResource, ISCMResourceGroup> |
SCMHistoryItemGroupTreeElement |
SCMHistoryItemTreeElement |
SCMHistoryItemChangeTreeElement |
IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement> |
SCMViewSeparatorElement;
type ShowChangesSetting = 'always' | 'never' | 'auto';
registerColor('scm.historyItemAdditionsForeground', {
dark: 'gitDecoration.addedResourceForeground',
light: 'gitDecoration.addedResourceForeground',
hcDark: 'gitDecoration.addedResourceForeground',
hcLight: 'gitDecoration.addedResourceForeground'
}, localize('scm.historyItemAdditionsForeground', "History item additions foreground color."));
registerColor('scm.historyItemDeletionsForeground', {
dark: 'gitDecoration.deletedResourceForeground',
light: 'gitDecoration.deletedResourceForeground',
hcDark: 'gitDecoration.deletedResourceForeground',
hcLight: 'gitDecoration.deletedResourceForeground'
}, localize('scm.historyItemDeletionsForeground', "History item deletions foreground color."));
registerColor('scm.historyItemStatisticsBorder', {
dark: transparent(foreground, 0.2),
light: transparent(foreground, 0.2),
hcDark: transparent(foreground, 0.2),
hcLight: transparent(foreground, 0.2)
}, localize('scm.historyItemStatisticsBorder', "History item statistics border color."));
registerColor('scm.historyItemSelectedStatisticsBorder', {
dark: transparent(listActiveSelectionForeground, 0.2),
light: transparent(listActiveSelectionForeground, 0.2),
hcDark: transparent(listActiveSelectionForeground, 0.2),
hcLight: transparent(listActiveSelectionForeground, 0.2)
}, localize('scm.historyItemSelectedStatisticsBorder', "History item selected statistics border color."));
interface ISCMLayout {
height: number | undefined;
width: number | undefined;
readonly onDidChange: Event<void>;
}
interface ActionButtonTemplate {
readonly actionButton: SCMActionButton;
disposable: IDisposable;
readonly templateDisposable: IDisposable;
}
export class ActionButtonRenderer implements ICompressibleTreeRenderer<ISCMActionButton, FuzzyScore, ActionButtonTemplate> {
static readonly DEFAULT_HEIGHT = 30;
static readonly TEMPLATE_ID = 'actionButton';
get templateId(): string { return ActionButtonRenderer.TEMPLATE_ID; }
private actionButtons = new Map<ISCMActionButton, SCMActionButton[]>();
constructor(
@ICommandService private commandService: ICommandService,
@IContextMenuService private contextMenuService: IContextMenuService,
@INotificationService private notificationService: INotificationService,
) { }
renderTemplate(container: HTMLElement): ActionButtonTemplate {
// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-no-twistie');
// Use default cursor & disable hover for list item
container.parentElement!.parentElement!.classList.add('cursor-default', 'force-no-hover');
const buttonContainer = append(container, $('.button-container'));
const actionButton = new SCMActionButton(buttonContainer, this.contextMenuService, this.commandService, this.notificationService);
return { actionButton, disposable: Disposable.None, templateDisposable: actionButton };
}
renderElement(node: ITreeNode<ISCMActionButton, FuzzyScore>, index: number, templateData: ActionButtonTemplate, height: number | undefined): void {
templateData.disposable.dispose();
const disposables = new DisposableStore();
const actionButton = node.element;
templateData.actionButton.setButton(node.element.button);
// Remember action button
const renderedActionButtons = this.actionButtons.get(actionButton) ?? [];
this.actionButtons.set(actionButton, [...renderedActionButtons, templateData.actionButton]);
disposables.add({
dispose: () => {
const renderedActionButtons = this.actionButtons.get(actionButton) ?? [];
const renderedWidgetIndex = renderedActionButtons.findIndex(renderedActionButton => renderedActionButton === templateData.actionButton);
if (renderedWidgetIndex < 0) {
throw new Error('Disposing unknown action button');
}
if (renderedActionButtons.length === 1) {
this.actionButtons.delete(actionButton);
} else {
renderedActionButtons.splice(renderedWidgetIndex, 1);
}
}
});
templateData.disposable = disposables;
}
renderCompressedElements(): void {
throw new Error('Should never happen since node is incompressible');
}
focusActionButton(actionButton: ISCMActionButton): void {
this.actionButtons.get(actionButton)?.forEach(renderedActionButton => renderedActionButton.focus());
}
disposeElement(node: ITreeNode<ISCMActionButton, FuzzyScore>, index: number, template: ActionButtonTemplate): void {
template.disposable.dispose();
}
disposeTemplate(templateData: ActionButtonTemplate): void {
templateData.disposable.dispose();
templateData.templateDisposable.dispose();
}
}
class SCMTreeDragAndDrop implements ITreeDragAndDrop<TreeElement> {
constructor(private readonly instantiationService: IInstantiationService) { }
getDragURI(element: TreeElement): string | null {
if (isSCMResource(element)) {
return element.sourceUri.toString();
}
return null;
}
onDragStart(data: IDragAndDropData, originalEvent: DragEvent): void {
const items = SCMTreeDragAndDrop.getResourcesFromDragAndDropData(data as ElementsDragAndDropData<TreeElement, TreeElement[]>);
if (originalEvent.dataTransfer && items?.length) {
this.instantiationService.invokeFunction(accessor => fillEditorsDragData(accessor, items, originalEvent));
const fileResources = items.filter(s => s.scheme === Schemas.file).map(r => r.fsPath);
if (fileResources.length) {
originalEvent.dataTransfer.setData(CodeDataTransfers.FILES, JSON.stringify(fileResources));
}
}
}
getDragLabel(elements: TreeElement[], originalEvent: DragEvent): string | undefined {
if (elements.length === 1) {
const element = elements[0];
if (isSCMResource(element)) {
return basename(element.sourceUri);
}
}
return String(elements.length);
}
onDragOver(data: IDragAndDropData, targetElement: TreeElement | undefined, targetIndex: number | undefined, targetSector: ListViewTargetSector | undefined, originalEvent: DragEvent): boolean | ITreeDragOverReaction {
return true;
}
drop(data: IDragAndDropData, targetElement: TreeElement | undefined, targetIndex: number | undefined, targetSector: ListViewTargetSector | undefined, originalEvent: DragEvent): void { }
private static getResourcesFromDragAndDropData(data: ElementsDragAndDropData<TreeElement, TreeElement[]>): URI[] {
const uris: URI[] = [];
for (const element of [...data.context ?? [], ...data.elements]) {
if (isSCMResource(element)) {
uris.push(element.sourceUri);
}
}
return uris;
}
dispose(): void { }
}
interface InputTemplate {
readonly inputWidget: SCMInputWidget;
inputWidgetHeight: number;
readonly elementDisposables: DisposableStore;
readonly templateDisposable: IDisposable;
}
class InputRenderer implements ICompressibleTreeRenderer<ISCMInput, FuzzyScore, InputTemplate> {
static readonly DEFAULT_HEIGHT = 26;
static readonly TEMPLATE_ID = 'input';
get templateId(): string { return InputRenderer.TEMPLATE_ID; }
private inputWidgets = new Map<ISCMInput, SCMInputWidget[]>();
private contentHeights = new WeakMap<ISCMInput, number>();
private editorSelections = new WeakMap<ISCMInput, Selection[]>();
constructor(
private outerLayout: ISCMLayout,
private overflowWidgetsDomNode: HTMLElement,
private updateHeight: (input: ISCMInput, height: number) => void,
@IInstantiationService private instantiationService: IInstantiationService
) { }
renderTemplate(container: HTMLElement): InputTemplate {
// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-no-twistie');
// Disable hover for list item
container.parentElement!.parentElement!.classList.add('force-no-hover');
const templateDisposable = new DisposableStore();
const inputElement = append(container, $('.scm-input'));
const inputWidget = this.instantiationService.createInstance(SCMInputWidget, inputElement, this.overflowWidgetsDomNode);
templateDisposable.add(inputWidget);
return { inputWidget, inputWidgetHeight: InputRenderer.DEFAULT_HEIGHT, elementDisposables: new DisposableStore(), templateDisposable };
}
renderElement(node: ITreeNode<ISCMInput, FuzzyScore>, index: number, templateData: InputTemplate): void {
const input = node.element;
templateData.inputWidget.setInput(input);
// Remember widget
const renderedWidgets = this.inputWidgets.get(input) ?? [];
this.inputWidgets.set(input, [...renderedWidgets, templateData.inputWidget]);
templateData.elementDisposables.add({
dispose: () => {
const renderedWidgets = this.inputWidgets.get(input) ?? [];
const renderedWidgetIndex = renderedWidgets.findIndex(renderedWidget => renderedWidget === templateData.inputWidget);
if (renderedWidgetIndex < 0) {
throw new Error('Disposing unknown input widget');
}
if (renderedWidgets.length === 1) {
this.inputWidgets.delete(input);
} else {
renderedWidgets.splice(renderedWidgetIndex, 1);
}
}
});
// Widget cursor selections
const selections = this.editorSelections.get(input);
if (selections) {
templateData.inputWidget.selections = selections;
}
templateData.elementDisposables.add(toDisposable(() => {
const selections = templateData.inputWidget.selections;
if (selections) {
this.editorSelections.set(input, selections);
}
}));
// Reset widget height so it's recalculated
templateData.inputWidgetHeight = InputRenderer.DEFAULT_HEIGHT;
// Rerender the element whenever the editor content height changes
const onDidChangeContentHeight = () => {
const contentHeight = templateData.inputWidget.getContentHeight();
this.contentHeights.set(input, contentHeight);
if (templateData.inputWidgetHeight !== contentHeight) {
this.updateHeight(input, contentHeight + 10);
templateData.inputWidgetHeight = contentHeight;
templateData.inputWidget.layout();
}
};
const startListeningContentHeightChange = () => {
templateData.elementDisposables.add(templateData.inputWidget.onDidChangeContentHeight(onDidChangeContentHeight));
onDidChangeContentHeight();
};
// Setup height change listener on next tick
disposableTimeout(startListeningContentHeightChange, 0, templateData.elementDisposables);
// Layout the editor whenever the outer layout happens
const layoutEditor = () => templateData.inputWidget.layout();
templateData.elementDisposables.add(this.outerLayout.onDidChange(layoutEditor));
layoutEditor();
}
renderCompressedElements(): void {
throw new Error('Should never happen since node is incompressible');
}
disposeElement(group: ITreeNode<ISCMInput, FuzzyScore>, index: number, template: InputTemplate): void {
template.elementDisposables.clear();
}
disposeTemplate(templateData: InputTemplate): void {
templateData.templateDisposable.dispose();
}
getHeight(input: ISCMInput): number {
return (this.contentHeights.get(input) ?? InputRenderer.DEFAULT_HEIGHT) + 10;
}
getRenderedInputWidget(input: ISCMInput): SCMInputWidget[] | undefined {
return this.inputWidgets.get(input);
}
getFocusedInput(): ISCMInput | undefined {
for (const [input, inputWidgets] of this.inputWidgets) {
for (const inputWidget of inputWidgets) {
if (inputWidget.hasFocus()) {
return input;
}
}
}
return undefined;
}
clearValidation(): void {
for (const [, inputWidgets] of this.inputWidgets) {
for (const inputWidget of inputWidgets) {
inputWidget.clearValidation();
}
}
}
}
interface ResourceGroupTemplate {
readonly name: HTMLElement;
readonly count: CountBadge;
readonly actionBar: ActionBar;
readonly elementDisposables: DisposableStore;
readonly disposables: IDisposable;
}
class ResourceGroupRenderer implements ICompressibleTreeRenderer<ISCMResourceGroup, FuzzyScore, ResourceGroupTemplate> {
static readonly TEMPLATE_ID = 'resource group';
get templateId(): string { return ResourceGroupRenderer.TEMPLATE_ID; }
constructor(
private actionViewItemProvider: IActionViewItemProvider,
@ISCMViewService private scmViewService: ISCMViewService
) { }
renderTemplate(container: HTMLElement): ResourceGroupTemplate {
// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-twistie');
const element = append(container, $('.resource-group'));
const name = append(element, $('.name'));
const actionsContainer = append(element, $('.actions'));
const actionBar = new ActionBar(actionsContainer, { actionViewItemProvider: this.actionViewItemProvider });
const countContainer = append(element, $('.count'));
const count = new CountBadge(countContainer, {}, defaultCountBadgeStyles);
const disposables = combinedDisposable(actionBar);
return { name, count, actionBar, elementDisposables: new DisposableStore(), disposables };
}
renderElement(node: ITreeNode<ISCMResourceGroup, FuzzyScore>, index: number, template: ResourceGroupTemplate): void {
const group = node.element;
template.name.textContent = group.label;
template.actionBar.clear();
template.actionBar.context = group;
template.count.setCount(group.resources.length);
const menus = this.scmViewService.menus.getRepositoryMenus(group.provider);
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceGroupMenu(group), template.actionBar));
}
renderCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResourceGroup>, FuzzyScore>, index: number, templateData: ResourceGroupTemplate, height: number | undefined): void {
throw new Error('Should never happen since node is incompressible');
}
disposeElement(group: ITreeNode<ISCMResourceGroup, FuzzyScore>, index: number, template: ResourceGroupTemplate): void {
template.elementDisposables.clear();
}
disposeTemplate(template: ResourceGroupTemplate): void {
template.elementDisposables.dispose();
template.disposables.dispose();
}
}
interface ResourceTemplate {
element: HTMLElement;
name: HTMLElement;
fileLabel: IResourceLabel;
decorationIcon: HTMLElement;
actionBar: ActionBar;
actionBarMenu: IMenu | undefined;
readonly actionBarMenuListener: MutableDisposable<IDisposable>;
readonly elementDisposables: DisposableStore;
readonly disposables: IDisposable;
}
interface RenderedResourceData {
readonly tooltip: string;
readonly uri: URI;
readonly fileLabelOptions: Partial<IFileLabelOptions>;
readonly iconResource: ISCMResource | undefined;
}
class RepositoryPaneActionRunner extends ActionRunner {
constructor(private getSelectedResources: () => (ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>)[]) {
super();
}
protected override async runAction(action: IAction, context: ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>): Promise<any> {
if (!(action instanceof MenuItemAction)) {
return super.runAction(action, context);
}
const selection = this.getSelectedResources();
const contextIsSelected = selection.some(s => s === context);
const actualContext = contextIsSelected ? selection : [context];
const args = flatten(actualContext.map(e => ResourceTree.isResourceNode(e) ? ResourceTree.collect(e) : [e]));
await action.run(...args);
}
}
class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore | LabelFuzzyScore, ResourceTemplate> {
static readonly TEMPLATE_ID = 'resource';
get templateId(): string { return ResourceRenderer.TEMPLATE_ID; }
private readonly disposables = new DisposableStore();
private renderedResources = new Map<ResourceTemplate, RenderedResourceData>();
constructor(
private viewMode: () => ViewMode,
private labels: ResourceLabels,
private actionViewItemProvider: IActionViewItemProvider,
private actionRunner: ActionRunner,
@ILabelService private labelService: ILabelService,
@ISCMViewService private scmViewService: ISCMViewService,
@IThemeService private themeService: IThemeService
) {
themeService.onDidColorThemeChange(this.onDidColorThemeChange, this, this.disposables);
}
renderTemplate(container: HTMLElement): ResourceTemplate {
const element = append(container, $('.resource'));
const name = append(element, $('.name'));
const fileLabel = this.labels.create(name, { supportDescriptionHighlights: true, supportHighlights: true });
const actionsContainer = append(fileLabel.element, $('.actions'));
const actionBar = new ActionBar(actionsContainer, {
actionViewItemProvider: this.actionViewItemProvider,
actionRunner: this.actionRunner
});
const decorationIcon = append(element, $('.decoration-icon'));
const actionBarMenuListener = new MutableDisposable<IDisposable>();
const disposables = combinedDisposable(actionBar, fileLabel, actionBarMenuListener);
return { element, name, fileLabel, decorationIcon, actionBar, actionBarMenu: undefined, actionBarMenuListener, elementDisposables: new DisposableStore(), disposables };
}
renderElement(node: ITreeNode<ISCMResource, FuzzyScore | LabelFuzzyScore> | ITreeNode<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate): void {
const resourceOrFolder = node.element;
const iconResource = ResourceTree.isResourceNode(resourceOrFolder) ? resourceOrFolder.element : resourceOrFolder;
const uri = ResourceTree.isResourceNode(resourceOrFolder) ? resourceOrFolder.uri : resourceOrFolder.sourceUri;
const fileKind = ResourceTree.isResourceNode(resourceOrFolder) ? FileKind.FOLDER : FileKind.FILE;
const tooltip = !ResourceTree.isResourceNode(resourceOrFolder) && resourceOrFolder.decorations.tooltip || '';
const hidePath = this.viewMode() === ViewMode.Tree;
let matches: IMatch[] | undefined;
let descriptionMatches: IMatch[] | undefined;
let strikethrough: boolean | undefined;
if (ResourceTree.isResourceNode(resourceOrFolder)) {
if (resourceOrFolder.element) {
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.element.resourceGroup.provider);
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder.element));
template.element.classList.toggle('faded', resourceOrFolder.element.decorations.faded);
strikethrough = resourceOrFolder.element.decorations.strikeThrough;
} else {
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.context.provider);
this._renderActionBar(template, resourceOrFolder, menus.getResourceFolderMenu(resourceOrFolder.context));
matches = createMatches(node.filterData as FuzzyScore | undefined);
template.element.classList.remove('faded');
}
} else {
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder));
[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
template.element.classList.toggle('faded', resourceOrFolder.decorations.faded);
strikethrough = resourceOrFolder.decorations.strikeThrough;
}
const renderedData: RenderedResourceData = {
tooltip, uri, fileLabelOptions: { hidePath, fileKind, matches, descriptionMatches, strikethrough }, iconResource
};
this.renderIcon(template, renderedData);
this.renderedResources.set(template, renderedData);
template.elementDisposables.add(toDisposable(() => this.renderedResources.delete(template)));
template.element.setAttribute('data-tooltip', tooltip);
}
disposeElement(resource: ITreeNode<ISCMResource, FuzzyScore | LabelFuzzyScore> | ITreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate): void {
template.elementDisposables.clear();
}
renderCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResource> | ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate, height: number | undefined): void {
const compressed = node.element as ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>;
const folder = compressed.elements[compressed.elements.length - 1];
const label = compressed.elements.map(e => e.name);
const fileKind = FileKind.FOLDER;
const matches = createMatches(node.filterData as FuzzyScore | undefined);
template.fileLabel.setResource({ resource: folder.uri, name: label }, {
fileDecorations: { colors: false, badges: true },
fileKind,
matches,
separator: this.labelService.getSeparator(folder.uri.scheme)
});
const menus = this.scmViewService.menus.getRepositoryMenus(folder.context.provider);
this._renderActionBar(template, folder, menus.getResourceFolderMenu(folder.context));
template.name.classList.remove('strike-through');
template.element.classList.remove('faded');
template.decorationIcon.style.display = 'none';
template.decorationIcon.style.backgroundImage = '';
template.element.setAttribute('data-tooltip', '');
}
disposeCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResource> | ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate, height: number | undefined): void {
template.elementDisposables.clear();
}
disposeTemplate(template: ResourceTemplate): void {
template.elementDisposables.dispose();
template.disposables.dispose();
}
private _renderActionBar(template: ResourceTemplate, resourceOrFolder: ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, menu: IMenu): void {
if (!template.actionBarMenu || template.actionBarMenu !== menu) {
template.actionBar.clear();
template.actionBarMenu = menu;
template.actionBarMenuListener.value = connectPrimaryMenuToInlineActionBar(menu, template.actionBar);
}
template.actionBar.context = resourceOrFolder;
}
private _processFilterData(uri: URI, filterData: FuzzyScore | LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];
}
if (!(filterData as LabelFuzzyScore).label) {
const matches = createMatches(filterData as FuzzyScore);
return [matches, undefined];
}
const fileName = basename(uri);
const label = (filterData as LabelFuzzyScore).label;
const pathLength = label.length - fileName.length;
const matches = createMatches((filterData as LabelFuzzyScore).score);
// FileName match
if (label === fileName) {
return [matches, undefined];
}
// FilePath match
const labelMatches: IMatch[] = [];
const descriptionMatches: IMatch[] = [];
for (const match of matches) {
if (match.start > pathLength) {
// Label match
labelMatches.push({
start: match.start - pathLength,
end: match.end - pathLength
});
} else if (match.end < pathLength) {
// Description match
descriptionMatches.push(match);
} else {
// Spanning match
labelMatches.push({
start: 0,
end: match.end - pathLength
});
descriptionMatches.push({
start: match.start,
end: pathLength
});
}
}
return [labelMatches, descriptionMatches];
}
private onDidColorThemeChange(): void {
for (const [template, data] of this.renderedResources) {
this.renderIcon(template, data);
}
}
private renderIcon(template: ResourceTemplate, data: RenderedResourceData): void {
const theme = this.themeService.getColorTheme();
const icon = theme.type === ColorScheme.LIGHT ? data.iconResource?.decorations.icon : data.iconResource?.decorations.iconDark;
template.fileLabel.setFile(data.uri, {
...data.fileLabelOptions,
fileDecorations: { colors: false, badges: !icon },
});
if (icon) {
if (ThemeIcon.isThemeIcon(icon)) {
template.decorationIcon.className = `decoration-icon ${ThemeIcon.asClassName(icon)}`;
if (icon.color) {
template.decorationIcon.style.color = theme.getColor(icon.color.id)?.toString() ?? '';
}
template.decorationIcon.style.display = '';
template.decorationIcon.style.backgroundImage = '';
} else {
template.decorationIcon.className = 'decoration-icon';
template.decorationIcon.style.color = '';
template.decorationIcon.style.display = '';
template.decorationIcon.style.backgroundImage = asCSSUrl(icon);
}
template.decorationIcon.title = data.tooltip;
} else {
template.decorationIcon.className = 'decoration-icon';
template.decorationIcon.style.color = '';
template.decorationIcon.style.display = 'none';
template.decorationIcon.style.backgroundImage = '';
template.decorationIcon.title = '';
}
}
dispose(): void {
this.disposables.dispose();
}
}
class HistoryItemGroupActionRunner extends ActionRunner {
protected override runAction(action: IAction, context: SCMHistoryItemGroupTreeElement): Promise<void> {
if (!(action instanceof MenuItemAction)) {
return super.runAction(action, context);
}
return action.run(context.repository.provider, context.id);
}
}
interface HistoryItemGroupTemplate {
readonly iconContainer: HTMLElement;
readonly label: IconLabel;
readonly toolBar: WorkbenchToolBar;
readonly count: CountBadge;
readonly elementDisposables: DisposableStore;
readonly templateDisposables: DisposableStore;
}
class HistoryItemGroupRenderer implements ICompressibleTreeRenderer<SCMHistoryItemGroupTreeElement, void, HistoryItemGroupTemplate> {
static readonly TEMPLATE_ID = 'history-item-group';
get templateId(): string { return HistoryItemGroupRenderer.TEMPLATE_ID; }
constructor(
readonly actionRunner: ActionRunner,
@IContextKeyService readonly contextKeyService: IContextKeyService,
@IContextMenuService readonly contextMenuService: IContextMenuService,
@IKeybindingService readonly keybindingService: IKeybindingService,
@IMenuService readonly menuService: IMenuService,
@ISCMViewService private readonly scmViewService: ISCMViewService,
@ITelemetryService readonly telemetryService: ITelemetryService
) { }
renderTemplate(container: HTMLElement) {
// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-twistie');
const element = append(container, $('.history-item-group'));
const label = new IconLabel(element, { supportIcons: true });
const iconContainer = prepend(label.element, $('.icon-container'));
const templateDisposables = new DisposableStore();
const toolBar = new WorkbenchToolBar(append(element, $('.actions')), { actionRunner: this.actionRunner, menuOptions: { shouldForwardArgs: true } }, this.menuService, this.contextKeyService, this.contextMenuService, this.keybindingService, this.telemetryService);
templateDisposables.add(toolBar);
const countContainer = append(element, $('.count'));
const count = new CountBadge(countContainer, {}, defaultCountBadgeStyles);
return { iconContainer, label, toolBar, count, elementDisposables: new DisposableStore(), templateDisposables };
}
renderElement(node: ITreeNode<SCMHistoryItemGroupTreeElement>, index: number, templateData: HistoryItemGroupTemplate, height: number | undefined): void {
const historyItemGroup = node.element;
templateData.iconContainer.className = 'icon-container';
if (historyItemGroup.icon && ThemeIcon.isThemeIcon(historyItemGroup.icon)) {
templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(historyItemGroup.icon));
}
templateData.label.setLabel(historyItemGroup.label, historyItemGroup.description, { title: historyItemGroup.ariaLabel });
templateData.count.setCount(historyItemGroup.count ?? 0);
const repositoryMenus = this.scmViewService.menus.getRepositoryMenus(historyItemGroup.repository.provider);
const historyProviderMenu = repositoryMenus.historyProviderMenu;
if (historyProviderMenu) {
const menu = historyProviderMenu.getHistoryItemGroupMenu(historyItemGroup);
const resetMenuId = historyItemGroup.direction === 'incoming' ? MenuId.SCMIncomingChanges : MenuId.SCMOutgoingChanges;
templateData.elementDisposables.add(connectPrimaryMenu(menu, (primary, secondary) => {
templateData.toolBar.setActions(primary, secondary, [resetMenuId]);
}));
templateData.toolBar.context = historyItemGroup;
} else {
templateData.toolBar.setActions([], []);
templateData.toolBar.context = undefined;
}
}
renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemGroupTreeElement>, void>, index: number, templateData: HistoryItemGroupTemplate, height: number | undefined): void {
throw new Error('Should never happen since node is incompressible');
}
disposeElement(node: ITreeNode<SCMHistoryItemGroupTreeElement>, index: number, templateData: HistoryItemGroupTemplate, height: number | undefined): void {
templateData.elementDisposables.clear();
}
disposeTemplate(templateData: HistoryItemGroupTemplate): void {
templateData.elementDisposables.dispose();
templateData.templateDisposables.dispose();
}
}
class HistoryItemActionRunner extends ActionRunner {
protected override async runAction(action: IAction, context: SCMHistoryItemTreeElement): Promise<any> {
if (!(action instanceof MenuItemAction)) {
return super.runAction(action, context);
}
const args: (ISCMProvider | ISCMHistoryItem)[] = [];
args.push(context.historyItemGroup.repository.provider);
args.push({
id: context.id,
parentIds: context.parentIds,
label: context.label,
description: context.description,
icon: context.icon,
timestamp: context.timestamp,
statistics: context.statistics,
} satisfies ISCMHistoryItem);
await action.run(...args);
}
}
interface HistoryItemTemplate {
readonly iconContainer: HTMLElement;
readonly label: IconLabel;
readonly statsContainer: HTMLElement;
readonly filesLabel: HTMLElement;
readonly insertionsLabel: HTMLElement;
readonly deletionsLabel: HTMLElement;
readonly actionBar: ActionBar;
readonly elementDisposables: DisposableStore;
readonly disposables: IDisposable;
}
class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTreeElement, LabelFuzzyScore, HistoryItemTemplate> {
static readonly TEMPLATE_ID = 'history-item';
get templateId(): string { return HistoryItemRenderer.TEMPLATE_ID; }
constructor(
private actionRunner: IActionRunner,
private actionViewItemProvider: IActionViewItemProvider,
@ISCMViewService private scmViewService: ISCMViewService) { }
renderTemplate(container: HTMLElement): HistoryItemTemplate {
// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-twistie');
const element = append(container, $('.history-item'));
const iconLabel = new IconLabel(element, { supportIcons: true, supportHighlights: true, supportDescriptionHighlights: true });
const iconContainer = prepend(iconLabel.element, $('.icon-container'));
const disposables = new DisposableStore();
const actionsContainer = append(element, $('.actions'));
const actionBar = new ActionBar(actionsContainer, { actionRunner: this.actionRunner, actionViewItemProvider: this.actionViewItemProvider });
disposables.add(actionBar);
const statsContainer = append(element, $('.stats-container'));
const filesLabel = append(statsContainer, $('.files-label'));
const insertionsLabel = append(statsContainer, $('.insertions-label'));
const deletionsLabel = append(statsContainer, $('.deletions-label'));
return { iconContainer, label: iconLabel, actionBar, statsContainer, filesLabel, insertionsLabel, deletionsLabel, elementDisposables: new DisposableStore(), disposables };
}
renderElement(node: ITreeNode<SCMHistoryItemTreeElement, LabelFuzzyScore>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
const historyItem = node.element;
templateData.iconContainer.className = 'icon-container';
if (historyItem.icon && ThemeIcon.isThemeIcon(historyItem.icon)) {
templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(historyItem.icon));
}
const [matches, descriptionMatches] = this.processMatches(historyItem, node.filterData);
templateData.label.setLabel(historyItem.label, historyItem.description, { matches, descriptionMatches });
templateData.actionBar.clear();
templateData.actionBar.context = historyItem;
const menus = this.scmViewService.menus.getRepositoryMenus(historyItem.historyItemGroup.repository.provider);
if (menus.historyProviderMenu) {
const historyItemMenu = menus.historyProviderMenu.getHistoryItemMenu(historyItem);
templateData.elementDisposables.add(connectPrimaryMenuToInlineActionBar(historyItemMenu, templateData.actionBar));
}
this.renderStatistics(node, index, templateData, height);
}
renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemTreeElement>, LabelFuzzyScore>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
throw new Error('Should never happen since node is incompressible');
}
private processMatches(historyItem: SCMHistoryItemTreeElement, filterData: LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];
}
return [
historyItem.label === filterData.label ? createMatches(filterData.score) : undefined,
historyItem.description === filterData.label ? createMatches(filterData.score) : undefined
];
}
private renderStatistics(node: ITreeNode<SCMHistoryItemTreeElement, LabelFuzzyScore>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
const historyItem = node.element;
if (historyItem.statistics) {
const statsAriaLabel: string[] = [
historyItem.statistics.files === 1 ?
localize('fileChanged', "{0} file changed", historyItem.statistics.files) :
localize('filesChanged', "{0} files changed", historyItem.statistics.files),
historyItem.statistics.insertions === 1 ? localize('insertion', "{0} insertion{1}", historyItem.statistics.insertions, '(+)') :
historyItem.statistics.insertions > 1 ? localize('insertions', "{0} insertions{1}", historyItem.statistics.insertions, '(+)') : '',
historyItem.statistics.deletions === 1 ? localize('deletion', "{0} deletion{1}", historyItem.statistics.deletions, '(-)') :
historyItem.statistics.deletions > 1 ? localize('deletions', "{0} deletions{1}", historyItem.statistics.deletions, '(-)') : ''
];
const statsTitle = statsAriaLabel
.filter(l => l !== '').join(', ');
templateData.statsContainer.title = statsTitle;
templateData.statsContainer.setAttribute('aria-label', statsTitle);
templateData.filesLabel.textContent = historyItem.statistics.files.toString();
templateData.insertionsLabel.textContent = historyItem.statistics.insertions > 0 ? `+${historyItem.statistics.insertions}` : '';
templateData.insertionsLabel.classList.toggle('hidden', historyItem.statistics.insertions === 0);
templateData.deletionsLabel.textContent = historyItem.statistics.deletions > 0 ? `-${historyItem.statistics.deletions}` : '';
templateData.deletionsLabel.classList.toggle('hidden', historyItem.statistics.deletions === 0);
}
templateData.statsContainer.classList.toggle('hidden', historyItem.statistics === undefined);