forked from kevadesu/forgejo
ui(git-grep): expose regexp mode in dropdown
This commit is contained in:
parent
6d6116857c
commit
663e957d3d
8 changed files with 66 additions and 20 deletions
|
@ -35,11 +35,22 @@ func Code(ctx *context.Context) {
|
|||
language := ctx.FormTrim("l")
|
||||
keyword := ctx.FormTrim("q")
|
||||
|
||||
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
||||
isFuzzy := true
|
||||
if mode := ctx.FormTrim("mode"); len(mode) > 0 {
|
||||
isFuzzy = mode == "fuzzy"
|
||||
} else {
|
||||
isFuzzy = ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
||||
}
|
||||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Language"] = language
|
||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||
ctx.Data["IsFuzzy"] = isFuzzy
|
||||
if isFuzzy {
|
||||
ctx.Data["CodeSearchMode"] = "fuzzy"
|
||||
} else {
|
||||
ctx.Data["CodeSearchMode"] = "exact"
|
||||
}
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
|
||||
if keyword == "" {
|
||||
|
|
|
@ -27,7 +27,7 @@ const (
|
|||
|
||||
func searchModeFromString(s string) searchMode {
|
||||
switch s {
|
||||
case "fuzzy":
|
||||
case "fuzzy", "union":
|
||||
return FuzzySearchMode
|
||||
case "regexp":
|
||||
return RegExpSearchMode
|
||||
|
@ -65,7 +65,7 @@ func Search(ctx *context.Context) {
|
|||
ctx.Data["Language"] = language
|
||||
ctx.Data["IsFuzzy"] = mode == FuzzySearchMode
|
||||
ctx.Data["IsRegExp"] = mode == RegExpSearchMode
|
||||
ctx.Data["SearchMode"] = mode.String()
|
||||
ctx.Data["CodeSearchMode"] = mode.String()
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
|
||||
if keyword == "" {
|
||||
|
@ -102,6 +102,7 @@ func Search(ctx *context.Context) {
|
|||
} else {
|
||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
||||
}
|
||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||
} else {
|
||||
grepOpt := git.GrepOptions{
|
||||
ContextLineNumber: 1,
|
||||
|
@ -110,6 +111,7 @@ func Search(ctx *context.Context) {
|
|||
switch mode {
|
||||
case FuzzySearchMode:
|
||||
grepOpt.Mode = git.FixedAnyGrepMode
|
||||
ctx.Data["CodeSearchMode"] = "union"
|
||||
case RegExpSearchMode:
|
||||
grepOpt.Mode = git.RegExpGrepMode
|
||||
}
|
||||
|
@ -133,6 +135,7 @@ func Search(ctx *context.Context) {
|
|||
Lines: code_indexer.HighlightSearchResultCode(r.Filename, r.LineNumbers, r.HighlightedRanges, strings.Join(r.LineCodes, "\n")),
|
||||
})
|
||||
}
|
||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "union", "regexp"}
|
||||
}
|
||||
|
||||
ctx.Data["CodeIndexerDisabled"] = !setting.Indexer.RepoIndexerEnabled
|
||||
|
|
|
@ -40,11 +40,22 @@ func CodeSearch(ctx *context.Context) {
|
|||
language := ctx.FormTrim("l")
|
||||
keyword := ctx.FormTrim("q")
|
||||
|
||||
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
||||
isFuzzy := true
|
||||
if mode := ctx.FormTrim("mode"); len(mode) > 0 {
|
||||
isFuzzy = mode == "fuzzy"
|
||||
} else {
|
||||
isFuzzy = ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
||||
}
|
||||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Language"] = language
|
||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||
ctx.Data["IsFuzzy"] = isFuzzy
|
||||
if isFuzzy {
|
||||
ctx.Data["CodeSearchMode"] = "fuzzy"
|
||||
} else {
|
||||
ctx.Data["CodeSearchMode"] = "exact"
|
||||
}
|
||||
ctx.Data["IsCodePage"] = true
|
||||
|
||||
if keyword == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue