Merge pull request '[v10.0/forgejo] fix(code search): empty mode dropdown when keyword is empty' (#6442) from bp-v10.0/forgejo-c53d219 into v10.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6442
Reviewed-by: Shiny Nematoda <snematoda@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
0ko 2025-01-01 13:36:24 +00:00
commit 9e6c3f226c
2 changed files with 7 additions and 3 deletions

View file

@ -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

View file

@ -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)