diff --git a/lib/main.js b/lib/main.js index a3b97eb..c654f96 100644 --- a/lib/main.js +++ b/lib/main.js @@ -15,22 +15,30 @@ const {watchWindows} = require("./watchWindows"); const MAX_WAIT_FOR_RESULTS = 350; const cachedKeywords = new Map(); -function isKeyword(keyword) { +function isKeyword(keywords) { // Immediately handle the keyword if we've checked it before - if (cachedKeywords.has(keyword)) { - return cachedKeywords.get(keyword); + if (cachedKeywords.has(keywords[0])) { + return cachedKeywords.get(keywords[0]); } // Check for search engine keyword and remember if it is - if (Services.search.getEngineByAlias(keyword) != null) { - cachedKeywords.set(keyword, true); + if (Services.search.getEngineByAlias(keywords[0]) != null) { + cachedKeywords.set(keywords[0], true); return true; } // Asynchronously check for bookmark keywords - PlacesUtils.keywords.fetch(keyword).then(result => { - cachedKeywords.set(keyword, !!result); - }); + if (PlacesUtils.keywords) { + PlacesUtils.keywords.fetch(keywords[0]).then(result => { + cachedKeywords.set(keywords[0], !!result); + }); + // Fallback to sync API for Pale Moon + // Only let the location bar handle single-term keywords + // to allow searches to be selected from the autocomplete results + } else if (keywords.length == 1 && PlacesUtils.getURLAndPostDataForKeyword(keywords[0])[0] != null) { + cachedKeywords.set(keywords[0], true); + return true; + } // Just return false immediately and correctly handle in the future return false; @@ -58,7 +66,8 @@ watchWindows(function(window) { // Starting with Firefox 48 Beta 3, the only behavior is unified complete, so // automatically select the 1th result (default search is 0th result) - let targetIndex = 1; + // Use 0 for Pale Moon + let targetIndex = ~~(Services.appinfo.ID != "{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}"); // Figure out what part the user actually typed function getTyped() { @@ -86,7 +95,7 @@ watchWindows(function(window) { } // Check if the first word is a keyword (search or bookmark) - if (isKeyword(search.split(/\s+/)[0])) { + if (isKeyword(search.split(/\s+/))) { return true; } diff --git a/package.json b/package.json index e12b8fa..fb7aa6a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "dependencies": ["api-utils", "addon-kit"], "description": "Press enter in the AwesomeBar to select the first result (without pressing down)", "engines": { - "firefox": ">=48.0a1" + "firefox": ">=48.0a1", + "{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}": ">=27.1.0b1" }, "fullName": "Enter Selects", "id": "enter.selects@agadak.net",