From 4a77d67d1f6626ae3a444bd0e92b1df8003ae9f4 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 3 Sep 2022 20:26:00 -0500 Subject: [PATCH] autocomplete: fix completion of `ai:` metatag. Fix it so we don't show the `ai:` prefix in front of results in the autocomplete menu when completing the `ai: metatag. --- app/components/autocomplete_component.rb | 12 +++++++----- app/models/tag.rb | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/components/autocomplete_component.rb b/app/components/autocomplete_component.rb index 814bed231..e7a75f665 100644 --- a/app/components/autocomplete_component.rb +++ b/app/components/autocomplete_component.rb @@ -32,16 +32,18 @@ class AutocompleteComponent < ApplicationComponent end def highlight_result(result) - if result.type == "tag-word" - highlight_matching_words(result.value, query) - elsif result.type == "mention" - highlight_wildcard_match(result.label, query + "*") - elsif metatag.present? && metatag.value.include?("*") + if metatag.present? && metatag.value.include?("*") highlight_wildcard_match(result.label, metatag.value) elsif metatag.present? && metatag.name.in?(%w[pool favgroup]) highlight_wildcard_match(result.label, "*" + metatag.value + "*") + elsif metatag.present? && metatag.name.in?(%w[ai unaliased]) + highlight_matching_words(result.label, metatag.value) elsif metatag.present? highlight_wildcard_match(result.label, metatag.value + "*") + elsif result.type == "tag-word" + highlight_matching_words(result.value, query) + elsif result.type == "mention" + highlight_wildcard_match(result.label, query + "*") elsif query.include?("*") highlight_wildcard_match(result.value, query) else diff --git a/app/models/tag.rb b/app/models/tag.rb index 9cbe716f1..1e149d0a2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -256,7 +256,7 @@ class Tag < ApplicationRecord def split_words(name) return [name] if !parsable_into_words?(name) - name.split(WORD_DELIMITER_REGEX).compact_blank + name.split(WORD_DELIMITER_REGEX).reject(&:empty?) end # Parse the tag into plain words, removing punctuation and delimiters.