From f83af31a0013bf993c812ab62d77399f08fcc435 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 3 Sep 2022 19:10:58 -0500 Subject: [PATCH] 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`. --- app/components/autocomplete_component.rb | 4 +++- app/logical/autocomplete_service.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/components/autocomplete_component.rb b/app/components/autocomplete_component.rb index 160d2a957..814bed231 100644 --- a/app/components/autocomplete_component.rb +++ b/app/components/autocomplete_component.rb @@ -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]) diff --git a/app/logical/autocomplete_service.rb b/app/logical/autocomplete_service.rb index 00a7cad0c..317b030ef 100644 --- a/app/logical/autocomplete_service.rb +++ b/app/logical/autocomplete_service.rb @@ -362,7 +362,7 @@ class AutocompleteService # @return [Array] 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