Skip to content

Commit 5fcda6b

Browse files
authored
SCM - improve statistics badge (#198353)
1 parent e563d91 commit 5fcda6b

3 files changed

Lines changed: 61 additions & 48 deletions

File tree

build/lib/stylelint/vscode-known-variables.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@
499499
"--vscode-quickInputList-focusIconForeground",
500500
"--vscode-quickInputTitle-background",
501501
"--vscode-sash-hoverBorder",
502+
"--vscode-scm-historyItemAdditionsForeground",
503+
"--vscode-scm-historyItemDeletionsForeground",
504+
"--vscode-scm-historyItemStatisticsBorder",
502505
"--vscode-scrollbar-shadow",
503506
"--vscode-scrollbarSlider-activeBackground",
504507
"--vscode-scrollbarSlider-background",
@@ -789,4 +792,4 @@
789792
"--z-index-notebook-sticky-scroll",
790793
"--zoom-factor"
791794
]
792-
}
795+
}

src/vs/workbench/contrib/scm/browser/media/scm.css

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,50 +154,30 @@
154154
font-size: 11px;
155155
line-height: 11px;
156156
margin-left: 6px;
157-
color: var(--vscode-badge-foreground);
157+
gap: 4px;
158158
}
159159

160-
.scm-view .monaco-list .monaco-list-row.focused .history-item .stats-container,
161-
.scm-view .monaco-list .monaco-list-row.selected .history-item .stats-container,
162-
.scm-view .monaco-list .monaco-list-row.focused .history-item .stats-container .monaco-icon-label .codicon,
163-
.scm-view .monaco-list .monaco-list-row.selected .history-item .stats-container .monaco-icon-label .codicon {
164-
color: var(--vscode-badge-foreground);
165-
}
166-
167-
.scm-view .monaco-list-row .history-item .stats-container .monaco-icon-label {
160+
.scm-view .monaco-list-row .history-item .stats-container {
168161
min-height: 18px;
169-
padding: 0 2px;
162+
padding: 0 4px;
170163
border-radius: 2px;
171-
border: 1px solid var(--vscode-contrastBorder);
172-
background-color: var(--vscode-badge-background);
164+
border: 1px solid var(--vscode-scm-historyItemStatisticsBorder);
173165
}
174166

175-
.scm-view .monaco-list-row .history-item .stats-container .monaco-icon-label .codicon {
176-
color: var(--vscode-badge-foreground);
177-
margin: 0 1px;
178-
}
179-
180-
.scm-view .monaco-list-row .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-added,
181-
.scm-view .monaco-list-row.focused .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-added,
182-
.scm-view .monaco-list-row.selected .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-added {
183-
color: var(--vscode-editorGutter-addedBackground);
184-
margin-top: 1px;
185-
}
186-
187-
.scm-view .monaco-list-row .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-removed,
188-
.scm-view .monaco-list-row.focused .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-removed,
189-
.scm-view .monaco-list-row.selected .history-item .stats-container .monaco-icon-label .codicon.codicon-diff-removed {
190-
color: var(--vscode-editorGutter-deletedBackground);
191-
margin-top: 1px;
192-
}
193-
194-
.scm-view .monaco-list-row .history-item .stats-container .monaco-icon-label .monaco-highlighted-label {
167+
.scm-view .monaco-list-row .history-item .stats-container > .files-label,
168+
.scm-view .monaco-list-row .history-item .stats-container > .insertions-label,
169+
.scm-view .monaco-list-row .history-item .stats-container > .deletions-label {
195170
display: flex;
196171
align-items: center;
172+
opacity: 0.75;
197173
}
198174

199-
.scm-view .monaco-list-row .history-item .stats-container .codicon {
200-
font-size: 11px;
175+
.scm-view .monaco-list-row .history-item .stats-container > .insertions-label {
176+
color: var(--vscode-scm-historyItemAdditionsForeground);
177+
}
178+
179+
.scm-view .monaco-list-row .history-item .stats-container > .deletions-label {
180+
color: var(--vscode-scm-historyItemDeletionsForeground);
201181
}
202182

203183
.scm-view .monaco-list-row .history-item .monaco-icon-label .icon-container {

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
100100
import { EditOperation } from 'vs/editor/common/core/editOperation';
101101
import { stripIcons } from 'vs/base/common/iconLabels';
102102
import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
103+
import { registerColor, transparent } from 'vs/platform/theme/common/colorRegistry';
103104

104105
// type SCMResourceTreeNode = IResourceNode<ISCMResource, ISCMResourceGroup>;
105106
// type SCMHistoryItemChangeResourceTreeNode = IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>;
@@ -116,6 +117,28 @@ type TreeElement =
116117
IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement> |
117118
SCMViewSeparatorElement;
118119

120+
registerColor('scm.historyItemAdditionsForeground', {
121+
dark: 'gitDecoration.addedResourceForeground',
122+
light: 'gitDecoration.addedResourceForeground',
123+
hcDark: 'gitDecoration.addedResourceForeground',
124+
hcLight: 'gitDecoration.addedResourceForeground'
125+
}, localize('scm.historyItemAdditionsForeground', "History item additions foreground color."));
126+
127+
registerColor('scm.historyItemDeletionsForeground', {
128+
dark: 'gitDecoration.deletedResourceForeground',
129+
light: 'gitDecoration.deletedResourceForeground',
130+
hcDark: 'gitDecoration.deletedResourceForeground',
131+
hcLight: 'gitDecoration.deletedResourceForeground'
132+
}, localize('scm.historyItemDeletionsForeground', "History item deletions foreground color."));
133+
134+
registerColor('scm.historyItemStatisticsBorder', {
135+
dark: transparent('foreground', 0.1),
136+
light: transparent('foreground', 0.1),
137+
hcDark: transparent('foreground', 0.1),
138+
hcLight: transparent('foreground', 0.1)
139+
}, localize('scm.historyItemStatisticsBorder', "History item statistics border color."));
140+
141+
119142
interface ISCMLayout {
120143
height: number | undefined;
121144
width: number | undefined;
@@ -735,7 +758,9 @@ interface HistoryItemTemplate {
735758
readonly iconContainer: HTMLElement;
736759
readonly label: IconLabel;
737760
readonly statsContainer: HTMLElement;
738-
readonly statsLabel: IconLabel;
761+
readonly filesLabel: HTMLElement;
762+
readonly insertionsLabel: HTMLElement;
763+
readonly deletionsLabel: HTMLElement;
739764
readonly actionBar: ActionBar;
740765
readonly elementDisposables: DisposableStore;
741766
readonly disposables: IDisposable;
@@ -765,9 +790,11 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
765790
disposables.add(actionBar);
766791

767792
const statsContainer = append(element, $('.stats-container'));
768-
const statsLabel = new IconLabel(statsContainer, { supportIcons: true });
793+
const filesLabel = append(statsContainer, $('.files-label'));
794+
const insertionsLabel = append(statsContainer, $('.insertions-label'));
795+
const deletionsLabel = append(statsContainer, $('.deletions-label'));
769796

770-
return { iconContainer, label: iconLabel, actionBar, statsContainer, statsLabel, elementDisposables: new DisposableStore(), disposables };
797+
return { iconContainer, label: iconLabel, actionBar, statsContainer, filesLabel, insertionsLabel, deletionsLabel, elementDisposables: new DisposableStore(), disposables };
771798
}
772799

773800
renderElement(node: ITreeNode<SCMHistoryItemTreeElement, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
@@ -798,32 +825,35 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
798825
private renderStatistics(node: ITreeNode<SCMHistoryItemTreeElement, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
799826
const historyItem = node.element;
800827

801-
if (historyItem.statistics?.files || historyItem.statistics?.insertions || historyItem.statistics?.deletions) {
802-
const statsLabelTitle: string[] = [];
803-
804-
const filesLabel = historyItem.statistics?.files ? `${historyItem.statistics.files}$(files)` : '';
805-
const insertionsLabel = historyItem.statistics?.insertions ? ` ${historyItem.statistics.insertions}$(diff-added)` : '';
806-
const deletionsLabel = historyItem.statistics?.deletions ? ` ${historyItem.statistics.deletions}$(diff-removed)` : '';
828+
if (historyItem.statistics) {
829+
const statsAriaLabel: string[] = [];
807830

808831
if (historyItem.statistics?.files) {
809832
const filesDescription = historyItem.statistics.files === 1 ?
810833
localize('fileChanged', "file changed") : localize('filesChanged', "files changed");
811-
statsLabelTitle.push(`${historyItem.statistics.files} ${filesDescription}`);
834+
statsAriaLabel.push(`${historyItem.statistics.files} ${filesDescription}`);
812835
}
813836

814837
if (historyItem.statistics?.insertions) {
815838
const insertionsDescription = historyItem.statistics.insertions === 1 ?
816839
localize('insertion', "insertion{0}", '(+)') : localize('insertions', "insertions{0}", '(+)');
817-
statsLabelTitle.push(`${historyItem.statistics.insertions} ${insertionsDescription}`);
840+
statsAriaLabel.push(`${historyItem.statistics.insertions} ${insertionsDescription}`);
818841
}
819842

820843
if (historyItem.statistics?.deletions) {
821844
const deletionsDescription = historyItem.statistics.deletions === 1 ?
822845
localize('deletion', "deletion{0}", '(-)') : localize('deletions', "deletions{0}", '(-)');
823-
statsLabelTitle.push(`${historyItem.statistics.deletions} ${deletionsDescription}`);
846+
statsAriaLabel.push(`${historyItem.statistics.deletions} ${deletionsDescription}`);
824847
}
825848

826-
templateData.statsLabel.setLabel(`${filesLabel}${insertionsLabel}${deletionsLabel}`, undefined, { title: statsLabelTitle.join(', ') });
849+
const statsTitle = statsAriaLabel.join(', ');
850+
templateData.statsContainer.title = statsTitle;
851+
templateData.statsContainer.setAttribute('aria-label', statsTitle);
852+
853+
templateData.filesLabel.textContent = historyItem.statistics.files > 0 ? historyItem.statistics.files.toString() : '';
854+
templateData.insertionsLabel.textContent = historyItem.statistics.insertions > 0 ? `+${historyItem.statistics.insertions}` : '';
855+
templateData.deletionsLabel.textContent = historyItem.statistics.deletions > 0 ? `-${historyItem.statistics.deletions}` : '';
856+
827857
templateData.statsContainer.style.display = '';
828858
} else {
829859
templateData.statsContainer.style.display = 'none';

0 commit comments

Comments
 (0)