mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-27 16:33:52 +00:00
feat(diff): Add search and extension filter to diff sidebar (#37068)
Adds a search box and a file-extension filter to the pull request diff sidebar, so reviewers can narrow a large diff down to the files they care about. Both filters apply to the file tree and to the diff itself. The extension menu follows GitHub: extensions sorted alphabetically, dotfiles and extension-less files in their own buckets, and the selection kept in the same `file-filters[]` query parameter, so a filtered view is shareable and survives a reload. The menu can list every extension in a diff, so `createTippy` gains an opt-in `limitSizeToViewport` option that caps a popup to the space left in the viewport and scrolls its content. Popups that do not ask for it are unchanged. Closes https://github.com/go-gitea/gitea/issues/27256 Signed-off-by: silverwind <me@silverwind.io> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -35,7 +35,9 @@
|
||||
{{template "repo/diff/whitespace_dropdown" .}}
|
||||
{{template "repo/diff/options_dropdown" .}}
|
||||
{{if .PageIsPullFiles}}
|
||||
<div id="diff-commit-select" data-merge-base="{{$.CompareInfo.CompareBase}}" data-issuelink="{{$.Issue.Link}}" data-queryparams="?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}" data-filter_changes_by_commit="{{ctx.Locale.Tr "repo.pulls.filter_changes_by_commit"}}">
|
||||
<div id="diff-commit-select" data-merge-base="{{$.CompareInfo.CompareBase}}" data-issuelink="{{$.Issue.Link}}"
|
||||
data-queryparams="?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}"
|
||||
data-text-filter-changes-by-commit="{{ctx.Locale.Tr "repo.pulls.filter_changes_by_commit"}}">
|
||||
{{/* the following will be replaced by vue component, but this avoids any loading artifacts till the vue component is initialized */}}
|
||||
<div class="ui jump dropdown tiny basic button custom">
|
||||
{{svg "octicon-git-commit"}}
|
||||
@@ -61,7 +63,15 @@
|
||||
<div id="diff-container">
|
||||
{{if $showFileTree}}
|
||||
{{$.FileIconPoolHTML}}
|
||||
<div id="diff-file-tree" class="tw-hidden not-mobile"></div>
|
||||
<div id="diff-file-tree" class="tw-hidden not-mobile" data-locale="{{JsonUtils.EncodeToString (dict
|
||||
"filterFiles" (ctx.Locale.Tr "repo.diff.filter_files")
|
||||
"filterFilesClear" (ctx.Locale.Tr "repo.diff.filter_files_clear")
|
||||
"filterByFileExtension" (ctx.Locale.Tr "repo.diff.filter_by_file_extension")
|
||||
"fileExtensions" (ctx.Locale.Tr "repo.diff.file_extensions")
|
||||
"noFileExtension" (ctx.Locale.Tr "repo.diff.no_file_extension")
|
||||
"dotfileExtension" (ctx.Locale.Tr "repo.diff.dotfile_extension")
|
||||
"allFileExtensions" (ctx.Locale.Tr "repo.diff.all_file_extensions")
|
||||
)}}"></div>
|
||||
<script nonce="{{ctx.CspScriptNonce}}">
|
||||
if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('tw-hidden');
|
||||
</script>
|
||||
@@ -69,7 +79,13 @@
|
||||
{{if .DiffNotAvailable}}
|
||||
<h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
|
||||
{{else}}
|
||||
<div id="diff-file-boxes" class="sixteen wide column">
|
||||
<div id="diff-boxes-column">
|
||||
{{if $showFileTree}}
|
||||
<div id="diff-no-matches" class="empty-placeholder tw-hidden">
|
||||
<h2>{{ctx.Locale.Tr "repo.diff.no_files_matched"}}</h2>
|
||||
</div>
|
||||
{{end}}
|
||||
<div id="diff-file-boxes">
|
||||
{{range $i, $file := .Diff.Files}}
|
||||
{{/*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*/}}
|
||||
{{$isImage:= $file.IsBlobTypeImage}}
|
||||
@@ -206,13 +222,17 @@
|
||||
{{end}}
|
||||
|
||||
{{if .Diff.IsIncomplete}}
|
||||
<div class="diff-file-box file-content tw-mt-2" id="diff-incomplete">
|
||||
<h4 class="ui top attached header tw-font-normal flex-left-right">
|
||||
{{ctx.Locale.Tr "repo.diff.too_many_files"}}
|
||||
<a class="ui basic tiny button" id="diff-show-more-files" data-global-click="diffLoadMoreFiles" data-href="?skip-to={{.Diff.End}}&file-only=true">{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
|
||||
</h4>
|
||||
<div class="ui segment flex-left-right" id="diff-incomplete">
|
||||
<span id="diff-load-progress" class="tw-text-text-light-2" data-text-too-many-files="{{ctx.Locale.Tr "repo.diff.too_many_files"}}">
|
||||
{{ctx.Locale.Tr "repo.diff.too_many_files" (len .Diff.Files) .DiffShortStat.NumFiles}}
|
||||
</span>
|
||||
<a class="ui basic tiny button" id="diff-show-more-files" data-global-click="diffLoadMoreFiles" data-href="?skip-to={{.Diff.End}}&file-only=true"
|
||||
data-text-default="{{ctx.Locale.Tr "repo.diff.show_more"}}"
|
||||
data-text-matching="{{ctx.Locale.Tr "repo.diff.show_more_matching"}}"
|
||||
>{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user