1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 21:48:00 +01:00

Fix search suggestion issues.

--HG--
extra : rebase_source : 4aeeb43dc214f7ae2e8275fb6190556eade78890
This commit is contained in:
Kris Maglione
2014-03-10 19:33:36 -07:00
parent 6dda37dfb9
commit 1c6026c4b9
2 changed files with 39 additions and 4 deletions

View File

@@ -232,6 +232,31 @@ var Bookmarks = Module("bookmarks", {
}).toObject();
},
/**
* Returns true if the given search engine provides suggestions.
* engine based on the given *query*. The results are always in the
* form of an array of strings. If *callback* is provided, the
* request is executed asynchronously and *callback* is called on
* completion. Otherwise, the request is executed synchronously and
* the results are returned.
*
* @param {string} engineName The name of the search engine from
* which to request suggestions.
* @returns {boolean}
*/
hasSuggestions: function hasSuggestions(engineName, query, callback) {
const responseType = "application/x-suggestions+json";
if (hasOwnProperty(this.suggestionProviders, engineName))
return true;
let engine = hasOwnProperty(this.searchEngines, engineName) && this.searchEngines[engineName];
if (engine && engine.supportsResponseType(responseType))
return true;
return false;
},
/**
* Retrieves a list of search suggestions from the named search
* engine based on the given *query*. The results are always in the
@@ -697,16 +722,19 @@ var Bookmarks = Module("bookmarks", {
let engineList = (engineAliases || options["suggestengines"].join(",") || "google").split(",");
engineList.forEach(function (name) {
if (!bookmarks.hasSuggestions(name))
return;
var desc = name;
let engine = bookmarks.searchEngines[name];
if (engine)
var desc = engine.description;
else if (!hasOwnProperty(bookmarks.suggestionProviders, name))
return;
desc = engine.description;
let [, word] = /^\s*(\S+)/.exec(context.filter) || [];
if (!kludge && word == name) // FIXME: Check for matching keywords
return;
let ctxt = context.fork(name, 0);
ctxt.title = [/*L*/desc + " Suggestions"];
@@ -727,7 +755,12 @@ var Bookmarks = Module("bookmarks", {
ctxt.incomplete = false;
ctxt.completions = array.uniq(ctxt.completions.filter(c => compl.contains(c))
.concat(compl), true);
}, Cu.reportError);
}, function (e) {
ctxt.incomplete = false;
ctxt.completions = [];
if (e)
Cu.reportError(e);
});
});
};

View File

@@ -305,6 +305,8 @@ var HintSession = Class("HintSession", CommandMode, {
return false;
let computedStyle = doc.defaultView.getComputedStyle(elem, null);
if (!computedStyle)
return false;
if (computedStyle.visibility != "visible" || computedStyle.display == "none")
return false;
return true;