From f20e1d5bc90909a0ce1a5e9e77f2882f85133672 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 2 Sep 2022 14:13:16 -0500 Subject: [PATCH] autocomplete: fix highlighting of short searches. Fix a bug where tags weren't highlighted correctly when the search only contained one character. --- app/components/autocomplete_component.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/components/autocomplete_component.rb b/app/components/autocomplete_component.rb index 1a257bc31..160d2a957 100644 --- a/app/components/autocomplete_component.rb +++ b/app/components/autocomplete_component.rb @@ -24,8 +24,10 @@ class AutocompleteComponent < ApplicationComponent def highlight_antecedent(result) if result.type == "tag-word" highlight_matching_words(result.antecedent, query) - else + elsif query.include?("*") highlight_wildcard_match(result.antecedent, query) + else + highlight_wildcard_match(result.antecedent, query + "*") end end @@ -38,8 +40,10 @@ class AutocompleteComponent < ApplicationComponent highlight_wildcard_match(result.label, "*" + metatag.value + "*") elsif metatag.present? highlight_wildcard_match(result.label, metatag.value + "*") - else + elsif query.include?("*") highlight_wildcard_match(result.value, query) + else + highlight_wildcard_match(result.value, query + "*") end end