diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index a43744bffbc..34a273de1dd 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -95,9 +95,11 @@ import { replaceTagRenderer } from "discourse/lib/render-tag";
import { registerCustomLastUnreadUrlCallback } from "discourse/models/topic";
import { setNewCategoryDefaultColors } from "discourse/routes/new-category";
import { addSearchResultsCallback } from "discourse/lib/search";
+import { addOnKeyDownCallback } from "discourse/widgets/search-menu";
import {
addQuickSearchRandomTip,
addSearchSuggestion,
+ removeDefaultQuickSearchRandomTips,
} from "discourse/widgets/search-menu-results";
import { CUSTOM_USER_SEARCH_OPTIONS } from "select-kit/components/user-chooser";
import { downloadCalendar } from "discourse/lib/download-calendar";
@@ -1707,6 +1709,25 @@ class PluginApi {
downloadCalendar(title, dates);
}
+ /**
+ * Add a function to be called when there is a keyDown even on the search-menu widget.
+ * This function runs before the default logic, and if one callback returns a falsey value
+ * the logic chain will stop, to prevent the core behavior from occuring.
+ *
+ * Example usage:
+ * ```
+ * api.addSearchMenuOnKeyDownCallback((searchMenu, event) => {
+ * if (searchMenu.term === "stop") {
+ * return false;
+ * }
+ * });
+ * ```
+ *
+ */
+ addSearchMenuOnKeyDownCallback(fn) {
+ addOnKeyDownCallback(fn);
+ }
+
/**
* Add a quick search tip shown randomly when the search dropdown is invoked on desktop.
*
@@ -1726,6 +1747,19 @@ class PluginApi {
addQuickSearchRandomTip(tip);
}
+ /**
+ * Remove the default quick search tips shown randomly when the search dropdown is invoked on desktop.
+ *
+ * Usage:
+ * ```
+ * api.removeDefaultQuickSearchRandomTips();
+ * ```
+ *
+ */
+ removeDefaultQuickSearchRandomTips(tip) {
+ removeDefaultQuickSearchRandomTips(tip);
+ }
+
/**
* Add custom user search options.
* It is heavily correlated with `register_groups_callback_for_users_search_controller_action` which allows defining custom filter.
diff --git a/app/assets/javascripts/discourse/app/widgets/search-menu-results.js b/app/assets/javascripts/discourse/app/widgets/search-menu-results.js
index 70f20a255fd..243c0991dd3 100644
--- a/app/assets/javascripts/discourse/app/widgets/search-menu-results.js
+++ b/app/assets/javascripts/discourse/app/widgets/search-menu-results.js
@@ -8,12 +8,14 @@ import { dateNode } from "discourse/helpers/node";
import { emojiUnescape } from "discourse/lib/text";
import getURL from "discourse-common/lib/get-url";
import { h } from "virtual-dom";
-import hbs from "discourse/widgets/hbs-compiler";
+import widgetHbs from "discourse/widgets/hbs-compiler";
import highlightSearch from "discourse/lib/highlight-search";
import { iconNode } from "discourse-common/lib/icon-library";
import renderTag from "discourse/lib/render-tag";
import { MODIFIER_REGEXP } from "discourse/widgets/search-menu";
import User from "discourse/models/user";
+import { hbs } from "ember-cli-htmlbars";
+import RenderGlimmer from "discourse/widgets/render-glimmer";
const suggestionShortcuts = [
"in:title",
@@ -73,6 +75,10 @@ export function addQuickSearchRandomTip(tip) {
}
}
+export function removeDefaultQuickSearchRandomTips() {
+ QUICK_TIPS = QUICK_TIPS.filter((tip) => !DEFAULT_QUICK_TIPS.includes(tip));
+}
+
export function resetQuickSearchRandomTips() {
QUICK_TIPS = [].concat(DEFAULT_QUICK_TIPS);
}
@@ -284,7 +290,14 @@ createWidget("search-menu-results", {
tagName: "div.results",
html(attrs) {
- const { term, suggestionKeyword, results, searchTopics } = attrs;
+ const {
+ term,
+ suggestionKeyword,
+ inTopicContext,
+ results,
+ searchTopics,
+ onLinkClicked,
+ } = attrs;
if (suggestionKeyword) {
return this.attach("search-menu-assistant", {
@@ -385,9 +398,41 @@ createWidget("search-menu-results", {
}
}
+ content.push(
+ new RenderGlimmer(
+ this,
+ "div",
+ hbs`