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:
@@ -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])
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user