From 928f188689aad3d7706f416981c4458b30adb72a Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Wed, 10 Jul 2024 05:25:32 +0000 Subject: [PATCH] fix(code search): various ui/ux improvements raised by user research (#4332) various improvements from [user research](https://codeberg.org/forgejo/user-research/src/branch/main/interviews/2024-06/issues%28search%2Cfeatures%29%2Cselfhosting%2CCI%2Caccessibility%2Ccodesearch.md) - filenames are links to the respective files fixes: `fold menu: user clicked and expected to view file, instead the file collapsed` - refactor(searchfile.tmpl): ordered lists with lines grouped together instead of table fixes: `multiple matches per file are "merged", only visible in the code lines (no visual separation)` - feat: display fuzzy as "Either" when using git-grep which is much more accurate than "fuzzy" git-grep does not support fuzzy searching, in this context selecting fuzzy searching worked similar to an OR of white space separated keywords fixes: `typo doesn't bring results in fuzzy search` ---
Before ![1](https://codeberg.org/attachments/5173357f-8dce-470c-9a9e-84a30517c216)
After ![after](https://codeberg.org/attachments/f8ec15dd-08ce-41f2-9326-d823de6f2395)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4332 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Shiny Nematoda Co-committed-by: Shiny Nematoda --- options/locale/locale_en-US.ini | 2 ++ templates/shared/search/code/results.tmpl | 5 +++- templates/shared/search/code/search.tmpl | 8 ++++- templates/shared/search/combo_fuzzy.tmpl | 9 ++++-- templates/shared/search/fuzzy.tmpl | 17 +++++++++-- templates/shared/searchfile.tmpl | 35 ++++++++++++++-------- tests/integration/repo_search_test.go | 36 +++++++++++++++++++---- 7 files changed, 88 insertions(+), 24 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fc58c32cbe..e39328180c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -164,6 +164,8 @@ search = Search... type_tooltip = Search type fuzzy = Fuzzy fuzzy_tooltip = Include results that also match the search term closely +union = Union +union_tooltip = Include results that match any of the whitespace seperated keywords exact = Exact exact_tooltip = Include only results that match the exact search term repo_kind = Search repos... diff --git a/templates/shared/search/code/results.tmpl b/templates/shared/search/code/results.tmpl index 50d4a35c3c..fe375579bd 100644 --- a/templates/shared/search/code/results.tmpl +++ b/templates/shared/search/code/results.tmpl @@ -26,7 +26,10 @@ - {{.Filename}} {{else}} - {{.Filename}} + + {{/* + */}}{{.Filename}} + {{end}} {{ctx.Locale.Tr "repo.diff.view_file"}} diff --git a/templates/shared/search/code/search.tmpl b/templates/shared/search/code/search.tmpl index 37a23dc3d6..6a52bb9462 100644 --- a/templates/shared/search/code/search.tmpl +++ b/templates/shared/search/code/search.tmpl @@ -1,5 +1,11 @@
- {{template "shared/search/combo_fuzzy" dict "Value" .Keyword "Disabled" .CodeIndexerUnavailable "IsFuzzy" .IsFuzzy "Placeholder" (ctx.Locale.Tr "search.code_kind")}} + {{template "shared/search/combo_fuzzy" + dict + "Value" .Keyword + "Disabled" .CodeIndexerUnavailable + "IsFuzzy" .IsFuzzy + "Placeholder" (ctx.Locale.Tr "search.code_kind") + "CodeIndexerDisabled" $.CodeIndexerDisabled}}
diff --git a/templates/shared/search/combo_fuzzy.tmpl b/templates/shared/search/combo_fuzzy.tmpl index 3540a89ecb..38189b0518 100644 --- a/templates/shared/search/combo_fuzzy.tmpl +++ b/templates/shared/search/combo_fuzzy.tmpl @@ -1,10 +1,15 @@ {{/* 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 */}} -{{/* IsFuzzy - state of the fuzzy search toggle */}} +{{/* IsFuzzy - state of the fuzzy/union search toggle */}} +{{/* CodeIndexerDisabled (optional) - if the performed search is done using git-grep */}} {{/* Tooltip (optional) - a tooltip to be displayed on button hover */}}
{{template "shared/search/input" dict "Value" .Value "Disabled" .Disabled "Placeholder" .Placeholder}} - {{template "shared/search/fuzzy" dict "Disabled" .Disabled "IsFuzzy" .IsFuzzy}} + {{template "shared/search/fuzzy" + dict + "Disabled" .Disabled + "IsFuzzy" .IsFuzzy + "CodeIndexerDisabled" .CodeIndexerDisabled}} {{template "shared/search/button" dict "Disabled" .Disabled "Tooltip" .Tooltip}}
diff --git a/templates/shared/search/fuzzy.tmpl b/templates/shared/search/fuzzy.tmpl index 5c09d3c150..25cfc5762c 100644 --- a/templates/shared/search/fuzzy.tmpl +++ b/templates/shared/search/fuzzy.tmpl @@ -1,10 +1,21 @@ {{/* Disabled (optional) - if dropdown has to be disabled */}} {{/* IsFuzzy - state of the fuzzy search toggle */}} -