From 2a7280ac48c2663ca291251a2de766859dfd2eff Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 14 Oct 2021 15:24:11 -0400 Subject: [PATCH] FIX: Improve quick search speed and result highlights (#14610) --- .../javascripts/discourse/app/widgets/search-menu.js | 12 ++++++++---- .../discourse/tests/acceptance/search-test.js | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/widgets/search-menu.js b/app/assets/javascripts/discourse/app/widgets/search-menu.js index 47dc7870808..dbaf83564d4 100644 --- a/app/assets/javascripts/discourse/app/widgets/search-menu.js +++ b/app/assets/javascripts/discourse/app/widgets/search-menu.js @@ -15,7 +15,7 @@ import { CANCELLED_STATUS } from "discourse/lib/autocomplete"; const CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi; const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi; const SUGGESTIONS_REGEXP = /(in:|status:|order:|:)([a-zA-Z]*)$/gi; -export const TOPIC_REPLACE_REGEXP = /\stopic:\d+/i; +export const TOPIC_REPLACE_REGEXP = /\btopic:\d+\s?/i; export const MODIFIER_REGEXP = /.*(\#|\@|:).*$/gi; export const DEFAULT_TYPE_FILTER = "exclude_topics"; @@ -385,10 +385,14 @@ export default createWidget("search-menu", { const highlightTerm = searchData.term.replace(TOPIC_REPLACE_REGEXP, ""); this.searchService().set("highlightTerm", highlightTerm); } - searchData.loading = SearchHelper.includesTopics() ? true : false; - const delay = SearchHelper.includesTopics() ? 400 : 200; - discourseDebounce(SearchHelper, SearchHelper.perform, this, delay); + if (SearchHelper.includesTopics()) { + searchData.loading = true; + SearchHelper.perform(this); + } else { + searchData.loading = false; + discourseDebounce(SearchHelper, SearchHelper.perform, this, 400); + } }, moreOfType(type) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js index 9579165d6de..f384289ed2b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js @@ -197,6 +197,17 @@ acceptance("Search - Anonymous", function (needs) { "highlights the post correctly" ); + await fillIn("#search-term", "topic:280 interface"); + await focus("input#search-term"); + await triggerKeyEvent(".search-menu", "keydown", 40); + await click(document.activeElement); + + assert.equal( + query("#post_7 span.highlighted").textContent.trim(), + "interface", + "highlights the post when term is after modifier" + ); + await click(".clear-search"); assert.equal(query("#search-term").value, "", "clear button works"); });