fix(code search): empty mode dropdown when keyword is empty
(cherry picked from commit c53d21965a)
	
	
This commit is contained in:
		
					parent
					
						
							
								86a09562fd
							
						
					
				
			
			
				commit
				
					
						c7c7f69f82
					
				
			
		
					 2 changed files with 7 additions and 3 deletions
				
			
		| 
						 | 
					@ -67,6 +67,12 @@ func Search(ctx *context.Context) {
 | 
				
			||||||
	ctx.Data["CodeSearchPath"] = path
 | 
						ctx.Data["CodeSearchPath"] = path
 | 
				
			||||||
	ctx.Data["CodeSearchMode"] = mode.String()
 | 
						ctx.Data["CodeSearchMode"] = mode.String()
 | 
				
			||||||
	ctx.Data["PageIsViewCode"] = true
 | 
						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 == "" {
 | 
						if keyword == "" {
 | 
				
			||||||
		ctx.HTML(http.StatusOK, tplSearch)
 | 
							ctx.HTML(http.StatusOK, tplSearch)
 | 
				
			||||||
| 
						 | 
					@ -103,7 +109,6 @@ func Search(ctx *context.Context) {
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
 | 
								ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		grepOpt := git.GrepOptions{
 | 
							grepOpt := git.GrepOptions{
 | 
				
			||||||
			ContextLineNumber: 1,
 | 
								ContextLineNumber: 1,
 | 
				
			||||||
| 
						 | 
					@ -139,10 +144,8 @@ func Search(ctx *context.Context) {
 | 
				
			||||||
					strings.Join(r.LineCodes, "\n")),
 | 
										strings.Join(r.LineCodes, "\n")),
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ctx.Data["CodeSearchOptions"] = git.GrepSearchOptions
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.Data["CodeIndexerDisabled"] = !setting.Indexer.RepoIndexerEnabled
 | 
					 | 
				
			||||||
	ctx.Data["Repo"] = ctx.Repo.Repository
 | 
						ctx.Data["Repo"] = ctx.Repo.Repository
 | 
				
			||||||
	ctx.Data["SourcePath"] = ctx.Repo.Repository.Link()
 | 
						ctx.Data["SourcePath"] = ctx.Repo.Repository.Link()
 | 
				
			||||||
	ctx.Data["SearchResults"] = searchResults
 | 
						ctx.Data["SearchResults"] = searchResults
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,6 +78,7 @@ func testSearchRepo(t *testing.T, indexer bool) {
 | 
				
			||||||
		code_indexer.UpdateRepoIndexer(repo)
 | 
							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", []string{"a.txt"}, indexer)
 | 
				
			||||||
	testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
 | 
						testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue