Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix #447, rename fancy search to be normal search
Browse files Browse the repository at this point in the history
This removes navigation.search, and makes search.search the default intent.

Also fix #448, make the card image clickable (focusing the search results)
  • Loading branch information
ianb committed Oct 22, 2019
1 parent 5447809 commit c9cb76e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion extension/background/intentParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
this.intentParser = (function() {
const exports = {};

const DEFAULT_INTENT = "navigation.search";
const DEFAULT_INTENT = "search.search";
const DEFAULT_SLOT = "query";

/*
Expand Down
2 changes: 2 additions & 0 deletions extension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 0 additions & 19 deletions extension/intents/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions extension/intents/search/queryScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ this.queryScript = (function() {
hasSidebarCard,
hasCard,
searchResults,
searchUrl: location.href,
};
});

Expand Down
30 changes: 25 additions & 5 deletions extension/intents/search/search.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -66,6 +81,7 @@ this.intents.search = (function() {
type: "showSearchResults",
card,
searchResults: searchInfo.searchResults,
searchUrl: searchInfo.searchUrl,
index: -1,
});
} else {
Expand All @@ -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({
Expand All @@ -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) {
Expand All @@ -107,6 +124,7 @@ this.intents.search = (function() {
await browser.runtime.sendMessage({
type: "showSearchResults",
searchResults: lastSearchInfo.searchResults,
searchUrl: lastSearchInfo.searchUrl,
index: lastSearchIndex,
});
if (!lastTabId) {
Expand All @@ -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;
})();
4 changes: 4 additions & 0 deletions extension/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,7 @@ a#lexicon {
color: #777;
font-size: 90%;
}

#search-image {
cursor: pointer;
}
2 changes: 1 addition & 1 deletion extension/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<!-- FIXME: alt="" isn't correct here: -->
<img id="search-image" style="display: none" alt="" />
<div id="search-show-next" style="display: none">
Say <strong>fancy search next</strong> to view: <br />
Say <strong>next result</strong> to view: <br />
<strong id="search-show-next-title"></strong>
<span id="search-show-next-domain"></span>
</div>
Expand Down
8 changes: 8 additions & 0 deletions extension/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ this.popup = (function() {
let stream;
let isWaitingForPermission = null;
let executedIntent = false;
let lastSearchUrl;

const { backgroundTabRecorder } = buildSettings;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
}
Expand Down
11 changes: 11 additions & 0 deletions extension/popup/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
})();

0 comments on commit c9cb76e

Please sign in to comment.