From 993736d838c36e26951b6cfea9c6a549958addd1 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 26 Apr 2024 19:21:04 +0800 Subject: [PATCH] Fix code search input for different views (#30678) 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 | 2 -- routers/web/repo/compare.go | 1 - routers/web/repo/pull.go | 1 - templates/repo/home.tmpl | 22 ++++++++++++---------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 8543fa44cc..a2c6ac33e8 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -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) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 035a92f228..a55426dab5 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index acdba4bcdc..7f131f2e98 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -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") diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 7b37ac1011..eb9eb9c149 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -90,7 +90,16 @@ {{ctx.Locale.Tr "repo.use_template"}} {{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) */}} +
+
+ + {{template "shared/search/button"}} +
+
+ {{else}} {{StringUtils.EllipsisString .Repository.Name 30}} {{- range $i, $v := .TreeNames -}} @@ -103,13 +112,6 @@ {{- end -}} {{end}} - -
-
- - {{template "shared/search/button"}} -
-
@@ -136,7 +138,7 @@
{{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 */}} {{svg "octicon-history" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.file_history"}} @@ -147,7 +149,7 @@ {{template "repo/view_file" .}} {{else if .IsBlame}} {{template "repo/blame" .}} - {{else}} + {{else}}{{/* IsViewDirectory */}} {{template "repo/view_list" .}} {{end}}