1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 19:12:26 +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 (Виктор Кожухаров) * Viktor Kojouharov (Виктор Кожухаров)
Patches (in no special order): Patches (in no special order):
* M.Terada (suggest engines)
* Muthu Kannan (ctrl-v support) * Muthu Kannan (ctrl-v support)
* Lars Kindler (:buffer(s) functionality) * Lars Kindler (:buffer(s) functionality)
* Lee Hinman (:open ./.. support) * 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. <b>Note:</b> If you don't wish to appear on this list when making a donation, please tell me.
2008: 2008:
* Guillaume Lovet * Spike Spiegal
* Mark Hashimoto * Mark Hashimoto
* Anirudh Sanjeev * Anirudh Sanjeev
* Ted Pavlic * Ted Pavlic
@@ -11,7 +11,7 @@
* Gabriel Gellner * Gabriel Gellner
* Marco Candrian * Marco Candrian
* Ovidiu Curcan * Ovidiu Curcan
* Ivo-Jose Jimenez-Ramos * Ivo-Jose Jimenez-Ramos (2x)
* Andrew Pantyukhin * Andrew Pantyukhin
* Kurtis Rader * Kurtis Rader

3
NEWS
View File

@@ -11,7 +11,8 @@
of bringing up the bookmarks/history window of bringing up the bookmarks/history window
* IMPORTANT: "B" mapping now works just like :buffers, old bufferwindow will be removed * IMPORTANT: "B" mapping now works just like :buffers, old bufferwindow will be removed
at some time. Use B5gt to jump to the 5th tab. 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 * gi accepts now a count to jump to the nth input field
* ctrl-t on input fields starts a very basic vi-mode * ctrl-t on input fields starts a very basic vi-mode
* :play for playing a recorded macro * :play for playing a recorded macro

View File

@@ -178,19 +178,45 @@ liberator.Completion = function () //{{{
return [0, buildLongestCommonSubstring(mapped, filter)]; 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=" + if (!filter)
liberator.options.getPref("font.language.group", "en") + "&qu="; return [0,null];
var xhr = new XMLHttpRequest();
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);
var 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];
xhr.open("GET", endPoint + encodeURIComponent(filter), false); 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); xhr.send(null);
var response = window.eval(xhr.responseText)[1]; var results = window.eval(xhr.responseText)[1];
if (!results)
return;
results.forEach(function(item)
{
completions.push([(matches ? matches[1] : "") + item, name + " suggestion"]);
});
});
for each (var item in response)
completions.push([item, "Google Suggestion"]);
return [0, completions]; return [0, completions];
}, },
@@ -213,6 +239,7 @@ liberator.Completion = function () //{{{
} }
var cpt = complete || liberator.options["complete"]; var cpt = complete || liberator.options["complete"];
var suggestEngineAlias = liberator.options["suggestengines"] || "google";
// join all completion arrays together // join all completion arrays together
for (var i = 0; i < cpt.length; i++) for (var i = 0; i < cpt.length; i++)
{ {
@@ -224,8 +251,8 @@ liberator.Completion = function () //{{{
completions = completions.concat(liberator.bookmarks.get(filter)); completions = completions.concat(liberator.bookmarks.get(filter));
else if (cpt[i] == "h") else if (cpt[i] == "h")
completions = completions.concat(liberator.history.get(filter)); completions = completions.concat(liberator.history.get(filter));
else if (cpt[i] == "g") else if (cpt[i] == "S")
completions = completions.concat(this.googleSuggest(filter)[1]); completions = completions.concat(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
} }
return [start, completions]; return [start, completions];

View File

@@ -476,7 +476,10 @@ liberator.Events = function () //{{{
dump("waited: " + (now - then) + " ms\n"); dump("waited: " + (now - then) + " ms\n");
if (liberator.buffer.loaded > 0) if (liberator.buffer.loaded > 0)
{
liberator.sleep(250);
break; break;
}
else else
liberator.echo("Waiting for page to load..."); 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."); liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped.");
dump("done waiting: " + ret + "\n"); 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; return ret;
} }
@@ -784,8 +791,13 @@ liberator.Events = function () //{{{
evt.noremap = noremap; evt.noremap = noremap;
elem.dispatchEvent(evt); elem.dispatchEvent(evt);
// stop feeding keys if page loading failed // stop feeding keys if page loading failed
if (liberator.modes.isReplaying && !waitForPageLoaded()) if (liberator.modes.isReplaying)
{
if (!waitForPageLoaded())
return; return;
// else // a short break between keys often helps
// liberator.sleep(50);
}
} }
return true; return true;
}, },

View File

@@ -286,7 +286,23 @@ liberator.CommandLine = function () //{{{
"Items which are completed at the :[tab]open prompt", "Items which are completed at the :[tab]open prompt",
"charlist", "sfbh", "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"], liberator.options.add(["showmode", "smd"],

View File

@@ -129,7 +129,7 @@ Items which are completed at the [c]:[tab]open[c] prompt. Available items:
*f* Local files *f* Local files
*b* Bookmarks *b* Bookmarks
*h* History *h* History
*g* Google Suggestions *S* Suggest engines
------------------------------------- -------------------------------------
The order is important, so [c]:set complete=bs[c] would list bookmarks first, 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. 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'|
||'titlestring'|| string (default: "Vimperator") ||'titlestring'|| string (default: "Vimperator")
____ ____