Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down