From c53d21965a6b9d235aa38ec624ab7055cb84db70 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Wed, 1 Jan 2025 12:32:41 +0000 Subject: [PATCH] fix(code search): empty mode dropdown when keyword is empty --- routers/web/repo/search.go | 9 ++++++--- tests/integration/repo_search_test.go | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index f2264360ec..442034b287 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -67,6 +67,12 @@ func Search(ctx *context.Context) { ctx.Data["CodeSearchPath"] = path ctx.Data["CodeSearchMode"] = mode.String() ctx.Data["PageIsViewCode"] = true + ctx.Data["CodeIndexerDisabled"] = !setting.Indexer.RepoIndexerEnabled + if setting.Indexer.RepoIndexerEnabled { + ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions + } else { + ctx.Data["CodeSearchOptions"] = git.GrepSearchOptions + } if keyword == "" { ctx.HTML(http.StatusOK, tplSearch) @@ -103,7 +109,6 @@ func Search(ctx *context.Context) { } else { ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx) } - ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions } else { grepOpt := git.GrepOptions{ ContextLineNumber: 1, @@ -139,10 +144,8 @@ func Search(ctx *context.Context) { strings.Join(r.LineCodes, "\n")), }) } - ctx.Data["CodeSearchOptions"] = git.GrepSearchOptions } - ctx.Data["CodeIndexerDisabled"] = !setting.Indexer.RepoIndexerEnabled ctx.Data["Repo"] = ctx.Repo.Repository ctx.Data["SourcePath"] = ctx.Repo.Repository.Link() ctx.Data["SearchResults"] = searchResults diff --git a/tests/integration/repo_search_test.go b/tests/integration/repo_search_test.go index 259ba36d08..6189dc1150 100644 --- a/tests/integration/repo_search_test.go +++ b/tests/integration/repo_search_test.go @@ -78,6 +78,7 @@ func testSearchRepo(t *testing.T, indexer bool) { code_indexer.UpdateRepoIndexer(repo) } + testSearch(t, "/user2/glob/search?q=", []string{}, indexer) testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer) testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)