]> source.dussan.org Git - gitea.git/commitdiff
Fix code search input for different views (#30678)
authorwxiaoguang <wxiaoguang@gmail.com>
Fri, 26 Apr 2024 11:21:04 +0000 (19:21 +0800)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 11:21:04 +0000 (11:21 +0000)
Now only show the "code search" on the repo home page, because it only
does global search.
So do not show it when viewing file or directory to avoid misleading
users (it doesn't search in a directory)

routers/web/repo/commit.go
routers/web/repo/compare.go
routers/web/repo/pull.go
templates/repo/home.tmpl

index 8543fa44cc712d17b9a1451f274fcb7fdb09a3bb..a2c6ac33e8f8ed52e97e00e5abca41c03b9a3843 100644 (file)
@@ -212,8 +212,6 @@ func SearchCommits(ctx *context.Context) {
 
 // FileHistory show a file's reversions
 func FileHistory(ctx *context.Context) {
-       ctx.Data["IsRepoToolbarCommits"] = true
-
        fileName := ctx.Repo.TreePath
        if len(fileName) == 0 {
                Commits(ctx)
index 035a92f22830c2d268eefd20bea453c399653c41..a55426dab5055803c096245d47699a52e0ada0d7 100644 (file)
@@ -800,7 +800,6 @@ func CompareDiff(ctx *context.Context) {
        }
        ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
 
-       ctx.Data["IsRepoToolbarCommits"] = true
        ctx.Data["IsDiffCompare"] = true
        _, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
 
index acdba4bcdc0213bfa593b00f5cdb26578fd6f87c..7f131f2e984bcc1e15c5284bcab5d7bbdf726852 100644 (file)
@@ -1225,7 +1225,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
        ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
        ctx.Data["PageIsComparePull"] = true
        ctx.Data["IsDiffCompare"] = true
-       ctx.Data["IsRepoToolbarCommits"] = true
        ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
        ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
        upload.AddUploadContext(ctx, "comment")
index 7b37ac10118db86e6753a66e50e485ee527f0b81..eb9eb9c14932f568443625dbfc123cd3232ab95f 100644 (file)
                                                {{ctx.Locale.Tr "repo.use_template"}}
                                        </a>
                                {{end}}
-                               {{if (not $isHomepage)}}
+                               {{if $isHomepage}}
+                                       {{/* only show the "code search" on the repo home page, it only does global search,
+                                               so do not show it when viewing file or directory to avoid misleading users (it doesn't search in a directory) */}}
+                                       <form class="ignore-dirty" action="{{.RepoLink}}/search" method="get">
+                                               <div class="ui small action input">
+                                                       <input name="q" placeholder="{{ctx.Locale.Tr "search.code_kind"}}">
+                                                       {{template "shared/search/button"}}
+                                               </div>
+                                       </form>
+                               {{else}}
                                        <span class="breadcrumb repo-path tw-ml-1">
                                                <a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{StringUtils.EllipsisString .Repository.Name 30}}</a>
                                                {{- range $i, $v := .TreeNames -}}
                                                {{- end -}}
                                        </span>
                                {{end}}
-
-                               <form class="ignore-dirty" action="{{.RepoLink}}/search" method="get">
-                                       <div class="ui small action input">
-                                               <input name="q" value="{{.Keyword}}" placeholder="{{ctx.Locale.Tr "search.code_kind"}}">
-                                               {{template "shared/search/button"}}
-                                       </div>
-                               </form>
                        </div>
                        <div class="tw-flex tw-items-center">
                                <!-- Only show clone panel in repository home page -->
                                        </div>
                                        {{template "repo/cite/cite_modal" .}}
                                {{end}}
-                               {{if and (not $isHomepage) (not .IsViewFile) (not .IsBlame)}}
+                               {{if and (not $isHomepage) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
                                        <a class="ui button" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
                                                {{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}}
                                        </a>
                        {{template "repo/view_file" .}}
                {{else if .IsBlame}}
                        {{template "repo/blame" .}}
-               {{else}}
+               {{else}}{{/* IsViewDirectory */}}
                        {{template "repo/view_list" .}}
                {{end}}
        </div>