1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 04:47:59 +01:00

added search suggestions (thanks to M.Terada)

This commit is contained in:
Martin Stubenschrott
2008-04-23 18:00:52 +00:00
parent 545a0ffb25
commit b9327b6bf2
7 changed files with 89 additions and 20 deletions

View File

@@ -11,6 +11,7 @@ Inactive/former developers:
* Viktor Kojouharov (Виктор Кожухаров)
Patches (in no special order):
* M.Terada (suggest engines)
* Muthu Kannan (ctrl-v support)
* Lars Kindler (:buffer(s) functionality)
* Lee Hinman (:open ./.. support)

View File

@@ -2,7 +2,7 @@
<b>Note:</b> If you don't wish to appear on this list when making a donation, please tell me.
2008:
* Guillaume Lovet
* Spike Spiegal
* Mark Hashimoto
* Anirudh Sanjeev
* Ted Pavlic
@@ -11,7 +11,7 @@
* Gabriel Gellner
* Marco Candrian
* Ovidiu Curcan
* Ivo-Jose Jimenez-Ramos
* Ivo-Jose Jimenez-Ramos (2x)
* Andrew Pantyukhin
* Kurtis Rader

3
NEWS
View File

@@ -11,7 +11,8 @@
of bringing up the bookmarks/history window
* IMPORTANT: "B" mapping now works just like :buffers, old bufferwindow will be removed
at some time. Use B5gt to jump to the 5th tab.
* new "g" flag for "complete" to list google suggestions in :open vimp and pressing tab (disabled by default)
* new "S" flag for "complete" to list google suggestions in :open vimp and
pressing tab (disabled by default). Also added new 'suggestengines' option.
* gi accepts now a count to jump to the nth input field
* ctrl-t on input fields starts a very basic vi-mode
* :play for playing a recorded macro

View File

@@ -178,20 +178,46 @@ liberator.Completion = function () //{{{
return [0, buildLongestCommonSubstring(mapped, filter)];
},
googleSuggest: function(filter)
searchEngineSuggest: function(filter, engineAliases)
{
const endPoint = "http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=" +
liberator.options.getPref("font.language.group", "en") + "&qu=";
var xhr = new XMLHttpRequest();
var completions = [];
if (!filter)
return [0,null];
xhr.open("GET", endPoint + encodeURIComponent(filter), false);
xhr.send(null);
var response = window.eval(xhr.responseText)[1];
var engineList = (engineAliases || liberator.options["suggestengines"]).split(",");
var responseType = "application/x-suggestions+json";
var ss = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
for each (var item in response)
completions.push([item, "Google Suggestion"]);
return [0, completions];
var completions = [];
engineList.forEach (function(name)
{
var query = filter;
var queryURI;
var engine = ss.getEngineByAlias(name);
var reg = new RegExp("^\s*(" + name + "\\s+)(.*)$");
var matches = query.match(reg);
if (matches)
query = matches[2];
if (engine && engine.supportsResponseType(responseType))
queryURI = engine.getSubmission(query, responseType).uri.asciiSpec;
else
return;
var xhr = new XMLHttpRequest();
xhr.open("GET", queryURI, false);
xhr.send(null);
var results = window.eval(xhr.responseText)[1];
if (!results)
return;
results.forEach(function(item)
{
completions.push([(matches ? matches[1] : "") + item, name + " suggestion"]);
});
});
return [0, completions];
},
// filter a list of urls
@@ -213,6 +239,7 @@ liberator.Completion = function () //{{{
}
var cpt = complete || liberator.options["complete"];
var suggestEngineAlias = liberator.options["suggestengines"] || "google";
// join all completion arrays together
for (var i = 0; i < cpt.length; i++)
{
@@ -224,8 +251,8 @@ liberator.Completion = function () //{{{
completions = completions.concat(liberator.bookmarks.get(filter));
else if (cpt[i] == "h")
completions = completions.concat(liberator.history.get(filter));
else if (cpt[i] == "g")
completions = completions.concat(this.googleSuggest(filter)[1]);
else if (cpt[i] == "S")
completions = completions.concat(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
}
return [start, completions];

View File

@@ -476,7 +476,10 @@ liberator.Events = function () //{{{
dump("waited: " + (now - then) + " ms\n");
if (liberator.buffer.loaded > 0)
{
liberator.sleep(250);
break;
}
else
liberator.echo("Waiting for page to load...");
}
@@ -488,6 +491,10 @@ liberator.Events = function () //{{{
liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped.");
dump("done waiting: " + ret + "\n");
// sometimes the input widget had focus when replaying a macro
// maybe this call should be moved somewhere else?
// liberator.focusContent(true);
return ret;
}
@@ -784,8 +791,13 @@ liberator.Events = function () //{{{
evt.noremap = noremap;
elem.dispatchEvent(evt);
// stop feeding keys if page loading failed
if (liberator.modes.isReplaying && !waitForPageLoaded())
return;
if (liberator.modes.isReplaying)
{
if (!waitForPageLoaded())
return;
// else // a short break between keys often helps
// liberator.sleep(50);
}
}
return true;
},

View File

@@ -286,9 +286,25 @@ liberator.CommandLine = function () //{{{
"Items which are completed at the :[tab]open prompt",
"charlist", "sfbh",
{
validator: function (value) { return !/[^sfbhg]/.test(value); }
validator: function (value) { return !/[^sfbhS]/.test(value); }
});
liberator.options.add(["suggestengines"],
"Engine Alias which has a feature of suggest",
"stringlist", "google",
{
validator: function (value)
{
var ss = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
return value.split(",").every(function (item)
{
var e = ss.getEngineByAlias(item);
return (e && e.supportsResponseType("application/x-suggestions+json")) ? true : false;
});
}
});
liberator.options.add(["showmode", "smd"],
"Show the current mode in the command line",
"boolean", true);

View File

@@ -129,7 +129,7 @@ Items which are completed at the [c]:[tab]open[c] prompt. Available items:
*f* Local files
*b* Bookmarks
*h* History
*g* Google Suggestions
*S* Suggest engines
-------------------------------------
The order is important, so [c]:set complete=bs[c] would list bookmarks first,
@@ -420,6 +420,18 @@ Override the 'ignorecase' option if the pattern contains uppercase characters.
This is only used if the 'ignorecase' option is set.
____
|\'suggestengines'|
||'suggestengines' || stringlist (default: "google")
____
Set the search engines which can be used for completion suggestions.
Add "S" to the 'complete' option if you want use this feature.
Warning: This feature could make tab-completion slower because it needs to
wait for changes, so use it only if you have a fast internet connection.
____
|\'titlestring'|
||'titlestring'|| string (default: "Vimperator")
____