From c9cb76e99096db24130a7a8a5bb022fb6031e4ac Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Tue, 22 Oct 2019 17:48:29 -0500 Subject: [PATCH] Fix #447, rename fancy search to be normal search This removes navigation.search, and makes search.search the default intent. Also fix #448, make the card image clickable (focusing the search results) --- extension/background/intentParser.js | 2 +- extension/background/main.js | 2 ++ extension/intents/navigation/navigation.js | 19 -------------- extension/intents/search/queryScript.js | 1 + extension/intents/search/search.js | 30 ++++++++++++++++++---- extension/popup/popup.css | 4 +++ extension/popup/popup.html | 2 +- extension/popup/popup.js | 8 ++++++ extension/popup/ui.js | 11 ++++++++ 9 files changed, 53 insertions(+), 26 deletions(-) diff --git a/extension/background/intentParser.js b/extension/background/intentParser.js index f7643d9d1..cb405ccbe 100644 --- a/extension/background/intentParser.js +++ b/extension/background/intentParser.js @@ -2,7 +2,7 @@ this.intentParser = (function() { const exports = {}; - const DEFAULT_INTENT = "navigation.search"; + const DEFAULT_INTENT = "search.search"; const DEFAULT_SLOT = "query"; /* diff --git a/extension/background/main.js b/extension/background/main.js index 48bd80736..7c1ca0935 100644 --- a/extension/background/main.js +++ b/extension/background/main.js @@ -49,6 +49,8 @@ this.main = (function() { } else if (message.type === "onVoiceShimForward") { message.type = "onVoiceShim"; return browser.runtime.sendMessage(message); + } else if (message.type === "focusSearchResults") { + return intents.search.focusSearchResults(message); } else if (message.type === "voiceShimForward") { message.type = "voiceShim"; if (!recorderTabId) { diff --git a/extension/intents/navigation/navigation.js b/extension/intents/navigation/navigation.js index 594e709ae..79076635d 100644 --- a/extension/intents/navigation/navigation.js +++ b/extension/intents/navigation/navigation.js @@ -18,25 +18,6 @@ this.intents.navigation = (function() { }, }); - this.intentRunner.registerIntent({ - name: "navigation.search", - description: "Do a regular (Google) search", - examples: ["Search for hiking in Denver", "Look up recipes for fish tacos"], - match: ` - (do a |) (search | query | find | find me | google | look up | lookup | look on | look for) (google | the web | the internet |) (for |) [query] (on the web |) - `, - async run(context) { - const cardData = await searching.ddgEntitySearch(context.slots.query); - if (!cardData) { - // Default to Google Search - const url = searching.googleSearchUrl(context.slots.query, false); - await context.createTab({ url }); - } else { - context.showCard(cardData); - } - }, - }); - this.intentRunner.registerIntent({ name: "navigation.bangSearch", description: diff --git a/extension/intents/search/queryScript.js b/extension/intents/search/queryScript.js index 14ca669e8..c6b8a5561 100644 --- a/extension/intents/search/queryScript.js +++ b/extension/intents/search/queryScript.js @@ -18,6 +18,7 @@ this.queryScript = (function() { hasSidebarCard, hasCard, searchResults, + searchUrl: location.href, }; }); diff --git a/extension/intents/search/search.js b/extension/intents/search/search.js index 5e0e76b71..8a1ae731c 100644 --- a/extension/intents/search/search.js +++ b/extension/intents/search/search.js @@ -1,6 +1,7 @@ -/* globals intentRunner, log, searching, content */ +/* globals intentRunner, log, searching, content, browserUtil */ this.intents.search = (function() { + const exports = {}; let _searchTabId; const START_URL = "https://www.google.com"; let lastSearchInfo; @@ -46,12 +47,26 @@ this.intents.search = (function() { return browser.tabs.sendMessage(_searchTabId, message); } + exports.focusSearchResults = async message => { + const { searchUrl } = message; + const searchTabId = await openSearchTab(); + const tab = await browser.tabs.get(searchTabId); + if (tab.url !== searchUrl) { + await browser.tabs.update({ url: searchUrl }); + } + await browserUtil.makeTabActive(tab); + await browser.runtime.sendMessage({ + type: "closePopup", + time: 0, + }); + }; + intentRunner.registerIntent({ name: "search.search", description: "Experimental search interface; this does all searches in a special pinned tab, and if the search results in a card then a screenshot of the card is displayed in the popup. If there's no card, then the first search result is opened in a new tab.", match: ` - fancy (search |) [query] + (do a |) (search | query | find | find me | google | look up | lookup | look on | look for) (google | the web | the internet |) (for |) [query] (on the web |) `, async run(context) { await performSearch(context.slots.query); @@ -66,6 +81,7 @@ this.intents.search = (function() { type: "showSearchResults", card, searchResults: searchInfo.searchResults, + searchUrl: searchInfo.searchUrl, index: -1, }); } else { @@ -74,6 +90,7 @@ this.intents.search = (function() { await browser.runtime.sendMessage({ type: "showSearchResults", searchResults: searchInfo.searchResults, + searchUrl: searchInfo.searchUrl, index: 0, }); const tab = await browser.tabs.create({ @@ -89,7 +106,7 @@ this.intents.search = (function() { description: "If you've done a search then this will display the next search result. If the last search had a card, and no search result was opened, then this will open a new tab with the first search result.", match: ` - fancy next (result | search |) + (search |) next (search |) (result | item | page | article |) `, async run(context) { if (!lastSearchInfo) { @@ -107,6 +124,7 @@ this.intents.search = (function() { await browser.runtime.sendMessage({ type: "showSearchResults", searchResults: lastSearchInfo.searchResults, + searchUrl: lastSearchInfo.searchUrl, index: lastSearchIndex, }); if (!lastTabId) { @@ -123,12 +141,14 @@ this.intents.search = (function() { name: "search.show", description: "Focuses the special tab used for searching", match: ` - fancy (search | show |) results - fancy show + (open | show | focus) search (results |) + (open | show | focus) results `, async run(context) { const tabId = await openSearchTab(); await context.makeTabActive(tabId); }, }); + + return exports; })(); diff --git a/extension/popup/popup.css b/extension/popup/popup.css index 114f4736c..b132d9533 100644 --- a/extension/popup/popup.css +++ b/extension/popup/popup.css @@ -340,3 +340,7 @@ a#lexicon { color: #777; font-size: 90%; } + +#search-image { + cursor: pointer; +} diff --git a/extension/popup/popup.html b/extension/popup/popup.html index 3c9c64450..e019ab235 100644 --- a/extension/popup/popup.html +++ b/extension/popup/popup.html @@ -78,7 +78,7 @@ diff --git a/extension/popup/popup.js b/extension/popup/popup.js index e65165db3..a460b7fae 100644 --- a/extension/popup/popup.js +++ b/extension/popup/popup.js @@ -6,6 +6,7 @@ this.popup = (function() { let stream; let isWaitingForPermission = null; let executedIntent = false; + let lastSearchUrl; const { backgroundTabRecorder } = buildSettings; @@ -94,6 +95,12 @@ this.popup = (function() { text, }); }; + ui.onSearchImageClick = async () => { + await browser.runtime.sendMessage({ + type: "focusSearchResults", + searchUrl: lastSearchUrl, + }); + }; }; recorder.onEnd = json => { // Probably superfluous, since this is called in onProcessing: @@ -148,6 +155,7 @@ this.popup = (function() { } else if (message.type === "displayAutoplayFailure") { ui.displayAutoplayFailure(); } else if (message.type === "showSearchResults") { + lastSearchUrl = message.searchUrl; ui.showSearchResults(message); } } diff --git a/extension/popup/ui.js b/extension/popup/ui.js index 329cc5a75..3966763c8 100644 --- a/extension/popup/ui.js +++ b/extension/popup/ui.js @@ -86,6 +86,10 @@ this.ui = (function() { // can be overridden }; + exports.onSearchImageClick = function() { + // can be overridden + }; + function listenForText() { const textInput = document.getElementById("text-input-field"); textInput.focus(); @@ -295,11 +299,18 @@ this.ui = (function() { } }; + function listenForImageClick() { + document.querySelector("#search-image").addEventListener("click", () => { + exports.onSearchImageClick(); + }); + } + init(); listenForClose(); listenForSettings(); listenForBack(); listenForLexicon(); + listenForImageClick(); return exports; })();