A platform for community discussion. Free, open, simple.
FIX: search autocomplete with multiple tags (#38930)
David Battersby32e281872c0e
diff --git a/frontend/discourse/app/components/search-menu/results/assistant-item.gjs b/frontend/discourse/app/components/search-menu/results/assistant-item.gjsindex e9c226eceec..f3f0850deed 100644--- a/frontend/discourse/app/components/search-menu/results/assistant-item.gjs+++ b/frontend/discourse/app/components/search-menu/results/assistant-item.gjs@@ -49,10 +49,15 @@ export default class AssistantItem extends Component {get prefix() {let prefix = "";if (this.args.suggestionKeyword !== "+") {- prefix =- this.search.activeGlobalSearchTerm- ?.split(this.args.suggestionKeyword)[0]- .trim() || "";+ const term = this.search.activeGlobalSearchTerm || "";+ const lastIndex = term.lastIndexOf(this.args.suggestionKeyword);++ if (lastIndex > 0) {+ prefix = term.substring(0, lastIndex).trim();+ } else if (lastIndex < 0) {+ prefix = term.trim();+ }+if (prefix.length) {prefix = `${prefix} `;}diff --git a/spec/system/search_menu_hashtag_spec.rb b/spec/system/search_menu_hashtag_spec.rbnew file mode 100644index 00000000000..e97e4c43ac7--- /dev/null+++ b/spec/system/search_menu_hashtag_spec.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++describe "Search menu hashtag autocomplete" do+ let(:search_page) { PageObjects::Pages::Search.new }+ fab!(:user)+ fab!(:category) { Fabricate(:category, name: "UX", slug: "ux") }+ fab!(:tag) { Fabricate(:tag, name: "design") }++ before do+ SiteSetting.tagging_enabled = true+ Fabricate(:theme_site_setting_with_service, name: "enable_welcome_banner", value: false)+ sign_in(user)+ end++ it "preserves prior hashtag when selecting a suggestion for a second hashtag" do+ visit("/")+ search_page.click_search_icon+ search_page.type_in_search_menu("#ux #des")++ expect(page).to have_css(".search-menu-assistant-item.tag")+ find(".search-menu-assistant-item.tag", match: :first).click++ expect(page).to have_field("icon-search-input", with: "#ux #design")+ end+end