Skip to content

Commit 1837e64

Browse files
authored
Diff stat improvements (#13954)
* Diff stat improvements - Combine number to just total number of changes - Add tooltip over stats bar - Increase contrast on file name - Refactor classes and CSS to be more reusable * misc tweaks * make count bold
1 parent 3285bab commit 1837e64

File tree

4 files changed

+29
-43
lines changed

4 files changed

+29
-43
lines changed

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ diff.whitespace_ignore_all_whitespace = Ignore whitespace when comparing lines
17871787
diff.whitespace_ignore_amount_changes = Ignore changes in amount of whitespace
17881788
diff.whitespace_ignore_at_eol = Ignore changes in whitespace at EOL
17891789
diff.stats_desc = <strong> %d changed files</strong> with <strong>%d additions</strong> and <strong>%d deletions</strong>
1790+
diff.stats_desc_file = %d changes: %d additions and %d deletions
17901791
diff.bin = BIN
17911792
diff.view_file = View File
17921793
diff.file_before = Before

templates/repo/diff/box.tmpl

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
<ol class="diff-detail-box diff-stats detail-files hide" id="diff-files">
3737
{{range .Diff.Files}}
3838
<li>
39-
<div class="diff-counter count pull-right">
39+
<div class="diff-counter pull-right">
4040
{{if not .IsBin}}
41-
{{template "repo/diff/stats" .}}
41+
{{template "repo/diff/stats" dict "file" . "root" $}}
4242
{{else}}
4343
<span>{{$.i18n.Tr "repo.diff.bin"}}</span>
4444
{{end}}
@@ -53,9 +53,9 @@
5353
{{if $file.IsIncomplete}}
5454
<div class="diff-file-box diff-box file-content">
5555
<h4 class="ui top attached normal header rounded">
56-
<div class="diff-counter count ui left">
56+
<div class="diff-counter ui left">
5757
{{if not $file.IsRenamed}}
58-
{{template "repo/diff/stats" .}}
58+
{{template "repo/diff/stats" dict "file" . "root" $}}
5959
{{end}}
6060
</div>
6161
<span class="file">{{$file.Name}}</span>
@@ -87,11 +87,11 @@
8787
{{svg "octicon-chevron-down" 18}}
8888
</a>
8989
{{end}}
90-
<div class="diff-counter count">
90+
<div class="diff-counter">
9191
{{if $file.IsBin}}
9292
{{$.i18n.Tr "repo.diff.bin"}}
9393
{{else if not $file.IsRenamed}}
94-
{{template "repo/diff/stats" .}}
94+
{{template "repo/diff/stats" dict "file" . "root" $}}
9595
{{end}}
9696
</div>
9797
<span class="file">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}}</span>

templates/repo/diff/stats.tmpl

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
2-
<span class="bar">
3-
<div class="pull-left add" style="width: {{DiffStatsWidth .Addition .Deletion}}%"></div>
4-
<div class="pull-left del"></div>
1+
{{Add .file.Addition .file.Deletion}}
2+
<span class="diff-stats-bar poping up ml-2" data-content="{{.root.i18n.Tr "repo.diff.stats_desc_file" (Add .file.Addition .file.Deletion) .file.Addition .file.Deletion | Str2html}}" data-variation="wide">
3+
<div class="diff-stats-add-bar" style="width: {{DiffStatsWidth .file.Addition .file.Deletion}}%"></div>
54
</span>
6-
<span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>

web_src/less/_repository.less

+19-32
Original file line numberDiff line numberDiff line change
@@ -1563,29 +1563,8 @@
15631563
display: flex;
15641564
align-items: center;
15651565

1566-
.count {
1567-
margin-right: 12px;
1568-
font-size: 13px;
1569-
flex: 0 0 auto;
1570-
1571-
.bar {
1572-
background-color: var(--color-red);
1573-
height: 12px;
1574-
width: 40px;
1575-
display: inline-block;
1576-
margin: 2px 4px 0;
1577-
vertical-align: text-top;
1578-
1579-
.add {
1580-
background-color: var(--color-green);
1581-
height: 12px;
1582-
}
1583-
}
1584-
}
1585-
15861566
.file {
15871567
flex: 1;
1588-
color: var(--color-text-light-2);
15891568
word-break: break-all;
15901569
}
15911570

@@ -1768,17 +1747,6 @@
17681747
border-bottom: 1px dashed #dddddd;
17691748
padding-left: 6px;
17701749
}
1771-
1772-
.diff-counter {
1773-
margin-right: 15px;
1774-
1775-
.del {
1776-
color: var(--color-red);
1777-
}
1778-
.add {
1779-
color: var(--color-green);
1780-
}
1781-
}
17821750
}
17831751

17841752
.repo-search-result {
@@ -3142,6 +3110,25 @@ td.blob-excerpt {
31423110
border-radius: var(--border-radius) !important;
31433111
}
31443112

3113+
.diff-counter {
3114+
font-weight: 600;
3115+
margin-right: 8px;
3116+
}
3117+
3118+
.diff-stats-bar {
3119+
display: inline-block;
3120+
background-color: var(--color-red);
3121+
height: 12px;
3122+
width: 40px;
3123+
position: relative;
3124+
top: 2px;
3125+
3126+
.diff-stats-add-bar {
3127+
background-color: var(--color-green);
3128+
height: 100%;
3129+
}
3130+
}
3131+
31453132
/* prevent page shaking on language bar click */
31463133
.repository-summary-language-stats {
31473134
height: 48px;

0 commit comments

Comments
 (0)