autocomplete: fix usernames not being highlighted in @mentions.

Fix usernames not being highlighted when completing @mentions.

This also changes it so the autocomplete results don't include the '@'
in front of the name.

Minor breaking change to the /autocomplete.json API. Autocomplete
results for mentions now have the type `mention` instead of `user`.
This commit is contained in:
evazion
2022-09-03 19:10:58 -05:00
parent 03c02ef78e
commit f83af31a00
2 changed files with 4 additions and 2 deletions

View File

@@ -12,7 +12,7 @@ class AutocompleteComponent < ApplicationComponent
def link_to_result(result, &block)
case result.type
when "user"
when "user", "mention"
link_to user_path(result.id), class: "user-#{result.level}", "@click.prevent": "", &block
when "pool"
link_to pool_path(result.id), class: "pool-category-#{result.category}", "@click.prevent": "", &block
@@ -34,6 +34,8 @@ class AutocompleteComponent < ApplicationComponent
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?("*")
highlight_wildcard_match(result.label, metatag.value)
elsif metatag.present? && metatag.name.in?(%w[pool favgroup])

View File

@@ -362,7 +362,7 @@ class AutocompleteService
# @return [Array<Hash>] the autocomplete results
def autocomplete_mention(string)
autocomplete_user(string).map do |result|
{ **result, value: "@" + result[:value] }
{ **result, type: "mention", value: "@" + result[:value] }
end
end