FIX: Keep topic context when redirecting to full search (#14846)

FIX: Keep topic context when redirecting to full search (#14846)

diff --git a/app/assets/javascripts/discourse/app/widgets/search-menu.js b/app/assets/javascripts/discourse/app/widgets/search-menu.js
index 82f7855..ad03c11 100644
--- a/app/assets/javascripts/discourse/app/widgets/search-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/search-menu.js
@@ -204,6 +204,12 @@ export default createWidget("search-menu", {
 
       query += `q=${encodeURIComponent(searchData.term)}`;
 
+      const searchContext = this.searchContext();
+
+      if (searchContext?.type === "topic") {
+        query += encodeURIComponent(` topic:${searchContext.id}`);
+      }
+
       if (query) {
         params.push(query);
       }
diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
index 2f20541..d3f39ae 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
@@ -243,6 +243,44 @@ acceptance("Search - Anonymous", function (needs) {
     );
   });
 
+  test("topic search scope - keep 'in this topic' filter in full page search", async function (assert) {
+    await visit("/t/internationalization-localization/280/1");
+
+    await click("#search-button");
+
+    const firstResult =
+      ".search-menu .results .search-menu-assistant-item:first-child";
+
+    assert.strictEqual(
+      query(firstResult).textContent.trim(),
+      I18n.t("search.in_this_topic"),
+      "contenxtual topic search is first available option"
+    );
+
+    await fillIn("#search-term", "proper");
+    await focus("input#search-term");
+    await triggerKeyEvent(".search-menu", "keydown", 40);
+    await click(document.activeElement);
+
+    assert.ok(
+      exists(".search-menu .search-context"),
+      "search context indicator is visible"
+    );
+
+    await click(".show-advanced-search");
+
+    assert.strictEqual(
+      query(".full-page-search").value,
+      "proper topic:280",
+      "it goes to full search page and preserves search term + context"
+    );
+
+    assert.ok(
+      exists(".search-advanced-options"),
+      "advanced search is expanded"
+    );
+  });
+
   test("topic search scope - special case when matching a single user", async function (assert) {
     await visit("/t/internationalization-localization/280/1");
 

GitHub sha: e90f506bf847c5d63761af7e81c1009670905167

This commit appears in #14846 which was approved by eviltrout. It was merged by pmusaraj.