Skip to content

Commit 572f096

Browse files
silverwindGiteaBot
andauthored
Only show diff file tree when more than one file changed (#27775)
When 0 or 1 files changed in a diff, we don't need to show a file tree. This behaviour matches GitHub. Single-file diff after this change, note absence of button: <img width="1234" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/3618438b-e655-42a3-989f-f299267b2b8b"> Co-authored-by: Giteabot <teabot@gitea.io>
1 parent fba4ee7 commit 572f096

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

templates/repo/diff/box.tmpl

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
{{$showFileTree := (and (not .DiffNotAvailable) (gt .Diff.NumFiles 1))}}
12
<div>
23
<div class="diff-detail-box diff-box">
34
<div class="gt-df gt-ac gt-fw">
4-
{{if not .DiffNotAvailable}}
5+
{{if $showFileTree}}
56
<button class="diff-toggle-file-tree-button gt-df gt-ac not-mobile" data-show-text="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{ctx.Locale.Tr "repo.diff.hide_file_tree"}}">
67
{{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}}
78
{{svg "octicon-sidebar-collapse" 20 "icon gt-hidden"}}
@@ -15,6 +16,8 @@
1516
diffTreeBtn.querySelector(diffTreeIcon).classList.remove('gt-hidden');
1617
diffTreeBtn.setAttribute('data-tooltip-content', diffTreeBtn.getAttribute(diffTreeVisible ? 'data-hide-text' : 'data-show-text'));
1718
</script>
19+
{{end}}
20+
{{if not .DiffNotAvailable}}
1821
<div class="diff-detail-stats gt-df gt-ac gt-fw">
1922
{{svg "octicon-diff" 16 "gt-mr-2"}}{{ctx.Locale.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
2023
</div>
@@ -85,13 +88,15 @@
8588
<div id="diff-file-list"></div>
8689
{{end}}
8790
<div id="diff-container">
88-
{{if .DiffNotAvailable}}
89-
<h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
90-
{{else}}
91+
{{if $showFileTree}}
9192
<div id="diff-file-tree" class="gt-hidden"></div>
9293
<script>
9394
if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('gt-hidden');
9495
</script>
96+
{{end}}
97+
{{if .DiffNotAvailable}}
98+
<h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
99+
{{else}}
95100
<div id="diff-file-boxes" class="sixteen wide column">
96101
{{range $i, $file := .Diff.Files}}
97102
{{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}}

0 commit comments

Comments
 (0)