mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 22:16:14 +01:00
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
|
@ -82,12 +82,12 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
var results []*GrepResult
|
var results []*GrepResult
|
||||||
// -I skips binary files
|
// -I skips binary files
|
||||||
cmd := NewCommand(ctx, "grep",
|
cmd := NewCommand(ctx, "grep",
|
||||||
"-I", "--null", "--break", "--heading", "--column",
|
"-I", "--null", "--break", "--heading",
|
||||||
"--line-number", "--ignore-case", "--full-name")
|
"--line-number", "--ignore-case", "--full-name")
|
||||||
if opts.Mode == RegExpGrepMode {
|
if opts.Mode == RegExpGrepMode {
|
||||||
cmd.AddArguments("--perl-regexp")
|
cmd.AddArguments("--perl-regexp")
|
||||||
} else {
|
} else {
|
||||||
cmd.AddArguments("--fixed-strings")
|
cmd.AddArguments("--fixed-strings", "--column")
|
||||||
}
|
}
|
||||||
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
||||||
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
||||||
|
|
|
@ -173,6 +173,8 @@ union = Union
|
||||||
union_tooltip = Include results that match any of the whitespace seperated keywords
|
union_tooltip = Include results that match any of the whitespace seperated keywords
|
||||||
exact = Exact
|
exact = Exact
|
||||||
exact_tooltip = Include only results that match the exact search term
|
exact_tooltip = Include only results that match the exact search term
|
||||||
|
regexp = RegExp
|
||||||
|
regexp_tooltip = Include results that match the regular expression
|
||||||
repo_kind = Search repos...
|
repo_kind = Search repos...
|
||||||
user_kind = Search users...
|
user_kind = Search users...
|
||||||
org_kind = Search orgs...
|
org_kind = Search orgs...
|
||||||
|
|
|
@ -35,11 +35,22 @@ func Code(ctx *context.Context) {
|
||||||
language := ctx.FormTrim("l")
|
language := ctx.FormTrim("l")
|
||||||
keyword := ctx.FormTrim("q")
|
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["Keyword"] = keyword
|
||||||
ctx.Data["Language"] = language
|
ctx.Data["Language"] = language
|
||||||
|
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||||
ctx.Data["IsFuzzy"] = isFuzzy
|
ctx.Data["IsFuzzy"] = isFuzzy
|
||||||
|
if isFuzzy {
|
||||||
|
ctx.Data["CodeSearchMode"] = "fuzzy"
|
||||||
|
} else {
|
||||||
|
ctx.Data["CodeSearchMode"] = "exact"
|
||||||
|
}
|
||||||
ctx.Data["PageIsViewCode"] = true
|
ctx.Data["PageIsViewCode"] = true
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
|
|
|
@ -27,7 +27,7 @@ const (
|
||||||
|
|
||||||
func searchModeFromString(s string) searchMode {
|
func searchModeFromString(s string) searchMode {
|
||||||
switch s {
|
switch s {
|
||||||
case "fuzzy":
|
case "fuzzy", "union":
|
||||||
return FuzzySearchMode
|
return FuzzySearchMode
|
||||||
case "regexp":
|
case "regexp":
|
||||||
return RegExpSearchMode
|
return RegExpSearchMode
|
||||||
|
@ -65,7 +65,7 @@ func Search(ctx *context.Context) {
|
||||||
ctx.Data["Language"] = language
|
ctx.Data["Language"] = language
|
||||||
ctx.Data["IsFuzzy"] = mode == FuzzySearchMode
|
ctx.Data["IsFuzzy"] = mode == FuzzySearchMode
|
||||||
ctx.Data["IsRegExp"] = mode == RegExpSearchMode
|
ctx.Data["IsRegExp"] = mode == RegExpSearchMode
|
||||||
ctx.Data["SearchMode"] = mode.String()
|
ctx.Data["CodeSearchMode"] = mode.String()
|
||||||
ctx.Data["PageIsViewCode"] = true
|
ctx.Data["PageIsViewCode"] = true
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
|
@ -102,6 +102,7 @@ func Search(ctx *context.Context) {
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
||||||
}
|
}
|
||||||
|
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||||
} else {
|
} else {
|
||||||
grepOpt := git.GrepOptions{
|
grepOpt := git.GrepOptions{
|
||||||
ContextLineNumber: 1,
|
ContextLineNumber: 1,
|
||||||
|
@ -110,6 +111,7 @@ func Search(ctx *context.Context) {
|
||||||
switch mode {
|
switch mode {
|
||||||
case FuzzySearchMode:
|
case FuzzySearchMode:
|
||||||
grepOpt.Mode = git.FixedAnyGrepMode
|
grepOpt.Mode = git.FixedAnyGrepMode
|
||||||
|
ctx.Data["CodeSearchMode"] = "union"
|
||||||
case RegExpSearchMode:
|
case RegExpSearchMode:
|
||||||
grepOpt.Mode = git.RegExpGrepMode
|
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")),
|
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
|
ctx.Data["CodeIndexerDisabled"] = !setting.Indexer.RepoIndexerEnabled
|
||||||
|
|
|
@ -40,11 +40,22 @@ func CodeSearch(ctx *context.Context) {
|
||||||
language := ctx.FormTrim("l")
|
language := ctx.FormTrim("l")
|
||||||
keyword := ctx.FormTrim("q")
|
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["Keyword"] = keyword
|
||||||
ctx.Data["Language"] = language
|
ctx.Data["Language"] = language
|
||||||
|
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
||||||
ctx.Data["IsFuzzy"] = isFuzzy
|
ctx.Data["IsFuzzy"] = isFuzzy
|
||||||
|
if isFuzzy {
|
||||||
|
ctx.Data["CodeSearchMode"] = "fuzzy"
|
||||||
|
} else {
|
||||||
|
ctx.Data["CodeSearchMode"] = "exact"
|
||||||
|
}
|
||||||
ctx.Data["IsCodePage"] = true
|
ctx.Data["IsCodePage"] = true
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
<form class="ui form ignore-dirty">
|
<form class="ui form ignore-dirty">
|
||||||
{{template "shared/search/combo_fuzzy"
|
{{template "shared/search/combo_multi"
|
||||||
dict
|
dict
|
||||||
"Value" .Keyword
|
"Value" .Keyword
|
||||||
"Disabled" .CodeIndexerUnavailable
|
"Disabled" .CodeIndexerUnavailable
|
||||||
"IsFuzzy" .IsFuzzy
|
|
||||||
"Placeholder" (ctx.Locale.Tr "search.code_kind")
|
"Placeholder" (ctx.Locale.Tr "search.code_kind")
|
||||||
"CodeIndexerDisabled" $.CodeIndexerDisabled}}
|
"CodeIndexerDisabled" $.CodeIndexerDisabled
|
||||||
|
"Selected" $.CodeSearchMode
|
||||||
|
"Options" $.CodeSearchOptions}}
|
||||||
</form>
|
</form>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="ui user list">
|
<div class="ui user list">
|
||||||
|
|
24
templates/shared/search/combo_multi.tmpl
Normal file
24
templates/shared/search/combo_multi.tmpl
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{{/* Value - value of the search field (for search results page) */}}
|
||||||
|
{{/* Disabled (optional) - if search field/button has to be disabled */}}
|
||||||
|
{{/* Placeholder (optional) - placeholder text to be used */}}
|
||||||
|
{{/* Selected - the currently selected option */}}
|
||||||
|
{{/* Options - options available to choose from */}}
|
||||||
|
{{/* Tooltip (optional) - a tooltip to be displayed on button hover */}}
|
||||||
|
<div class="ui small fluid action input">
|
||||||
|
{{template "shared/search/input" dict "Value" .Value "Disabled" .Disabled "Placeholder" .Placeholder}}
|
||||||
|
<div class="ui small dropdown selection {{if .Disabled}} disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}">
|
||||||
|
<div class="text">
|
||||||
|
{{ctx.Locale.Tr (printf "search.%s" .Selected)}}
|
||||||
|
</div>
|
||||||
|
<div class="menu" data-test-tag="fuzzy-dropdown">
|
||||||
|
{{range $opt := .Options}}
|
||||||
|
{{$isActive := eq $.Selected $opt}}
|
||||||
|
<label class="{{if $isActive}}active {{end}}item" data-value="{{$opt}}" data-tooltip-content="{{ctx.Locale.Tr (printf "search.%s_tooltip" $opt)}}">
|
||||||
|
<input hidden type="radio" name="mode" value="{{$opt}}"{{if $isActive}} checked{{end}}/>
|
||||||
|
{{ctx.Locale.Tr (printf "search.%s" $opt)}}
|
||||||
|
</label>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{template "shared/search/button" dict "Disabled" .Disabled "Tooltip" .Tooltip}}
|
||||||
|
</div>
|
|
@ -1,21 +1,15 @@
|
||||||
{{/* Disabled (optional) - if dropdown has to be disabled */}}
|
{{/* Disabled (optional) - if dropdown has to be disabled */}}
|
||||||
{{/* IsFuzzy - state of the fuzzy search toggle */}}
|
{{/* IsFuzzy - state of the fuzzy search toggle */}}
|
||||||
<div class="ui small dropdown selection {{if .Disabled}} disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}" data-test-tag="fuzzy-dropdown">
|
<div class="ui small dropdown selection {{if .Disabled}} disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}">
|
||||||
{{$fuzzyType := "fuzzy"}}
|
|
||||||
{{if .CodeIndexerDisabled}}
|
|
||||||
{{$fuzzyType = "union"}}
|
|
||||||
{{end}}
|
|
||||||
<input name="fuzzy" type="hidden"{{if .Disabled}} disabled{{end}} value="{{.IsFuzzy}}">{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
<input name="fuzzy" type="hidden"{{if .Disabled}} disabled{{end}} value="{{.IsFuzzy}}">{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||||
<div class="text">{{/*
|
<div class="text">{{if .IsFuzzy}}{{/*
|
||||||
if code indexer is disabled display fuzzy as union
|
*/}}{{ctx.Locale.Tr "search.fuzzy"}}{{/*
|
||||||
*/}}{{if .IsFuzzy}}{{/*
|
|
||||||
*/}}{{ctx.Locale.Tr (printf "search.%s" $fuzzyType)}}{{/*
|
|
||||||
*/}}{{else}}{{/*
|
*/}}{{else}}{{/*
|
||||||
*/}}{{ctx.Locale.Tr "search.exact"}}{{/*
|
*/}}{{ctx.Locale.Tr "search.exact"}}{{/*
|
||||||
*/}}{{end}}</div>
|
*/}}{{end}}</div>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<div class="item" data-value="true" data-tooltip-content="{{ctx.Locale.Tr (printf "search.%s_tooltip" $fuzzyType)}}">{{/*
|
<div class="item" data-value="true" data-tooltip-content="{{ctx.Locale.Tr "search.fuzzy_tooltip"}}">{{/*
|
||||||
*/}}{{ctx.Locale.Tr (printf "search.%s" $fuzzyType)}}</div>
|
*/}}{{ctx.Locale.Tr "search.fuzzy"}}</div>
|
||||||
<div class="item" data-value="false" data-tooltip-content="{{ctx.Locale.Tr "search.exact_tooltip"}}">{{ctx.Locale.Tr "search.exact"}}</div>
|
<div class="item" data-value="false" data-tooltip-content="{{ctx.Locale.Tr "search.exact_tooltip"}}">{{ctx.Locale.Tr "search.exact"}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue