From 19059a46cb3bc44e9fd89800d52508cc6d8c852f Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Mon, 31 Mar 2008 13:22:47 +0000 Subject: [PATCH] added google suggestions to tab completion --- NEWS | 1 + content/completion.js | 19 +++++++++++++++++++ content/events.js | 5 +++-- content/ui.js | 2 +- locale/en-US/options.txt | 1 + 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 3425a373..850b49c6 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ 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) * 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 diff --git a/content/completion.js b/content/completion.js index 48f23194..9b987a00 100644 --- a/content/completion.js +++ b/content/completion.js @@ -177,6 +177,23 @@ liberator.Completion = function () //{{{ }); return [0, buildLongestCommonSubstring(mapped, filter)]; }, + + googleSuggest: function(filter) + { + 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 = []; + + xhr.open("GET", endPoint + encodeURIComponent(filter), false); + xhr.send(null); + var response = window.eval(xhr.responseText)[1]; + + for each (var item in response) + completions.push([item, "Google Suggestion"]); + return [0, completions]; + }, + // filter a list of urls // // may consist of search engines, filenames, bookmarks and history, @@ -207,6 +224,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]); } return [start, completions]; diff --git a/content/events.js b/content/events.js index 24fbb7c5..2371052c 100644 --- a/content/events.js +++ b/content/events.js @@ -903,8 +903,9 @@ liberator.Events = function () //{{{ // dump("=+++++++++=\n" + liberator.util.objectToString(event.target) + "\n") // dump (elem + ": " + win + "\n");//" - target: " + event.target + " - origtarget: " + event.originalTarget + " - expltarget: " + event.explicitOriginalTarget + "\n"); - if (elem && elem instanceof HTMLInputElement && - (elem.type.toLowerCase() == "text" || elem.type.toLowerCase() == "password")) + if (win == window.content && // don't store it if e.g. the command line has focus + elem && elem instanceof HTMLInputElement && + (elem.type.toLowerCase() == "text" || elem.type.toLowerCase() == "password")) { this.wantsModeReset = false; liberator.mode = liberator.modes.INSERT; diff --git a/content/ui.js b/content/ui.js index dc21b47b..75e1fb2f 100644 --- a/content/ui.js +++ b/content/ui.js @@ -286,7 +286,7 @@ liberator.CommandLine = function () //{{{ "Items which are completed at the :[tab]open prompt", "charlist", "sfbh", { - validator: function (value) { return !/[^sfbh]/.test(value); } + validator: function (value) { return !/[^sfbhg]/.test(value); } }); liberator.options.add(["showmode", "smd"], diff --git a/locale/en-US/options.txt b/locale/en-US/options.txt index a2fab7bc..f36f78f8 100644 --- a/locale/en-US/options.txt +++ b/locale/en-US/options.txt @@ -129,6 +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 ------------------------------------- The order is important, so [c]:set complete=bs[c] would list bookmarks first,