mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 16:52:25 +01:00
Make autocompletion generally more reasonable
This commit is contained in:
@@ -311,7 +311,8 @@ liberator.Bookmarks = function () //{{{
|
||||
{
|
||||
if (bypassCache) // Is this really necessary anymore?
|
||||
cache.load();
|
||||
return liberator.completion.filterURLArray(cache.bookmarks, filter, tags);
|
||||
return liberator.completion.cached(cache.bookmarks, filter, function () cache.bookmarks,
|
||||
"filterURLArray", tags);
|
||||
},
|
||||
|
||||
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
|
||||
@@ -709,8 +710,8 @@ liberator.History = function () //{{{
|
||||
if (!history)
|
||||
load();
|
||||
|
||||
return liberator.completion.filterURLArray(cachedHistory, filter).concat(
|
||||
liberator.completion.filterURLArray(history, filter));
|
||||
return liberator.completion.cached("history", filter, function() cachedHistory.concat(history),
|
||||
"filterURLArray");
|
||||
},
|
||||
|
||||
// the history is automatically added to the Places global history
|
||||
|
||||
@@ -36,6 +36,8 @@ liberator.Completion = function () //{{{
|
||||
.getService(Components.interfaces.nsIAutoCompleteSearch);
|
||||
|
||||
// the completion substrings, used for showing the longest common match
|
||||
var cacheFilter = {};
|
||||
var cacheResults = {};
|
||||
var substrings = [];
|
||||
var historyCache = [];
|
||||
var historyResult = null;
|
||||
@@ -184,6 +186,17 @@ liberator.Completion = function () //{{{
|
||||
return buildLongestCommonSubstring(array, filter, favicon);
|
||||
},
|
||||
|
||||
cached: function (key, filter, generate, method)
|
||||
{
|
||||
let oldFilter = cacheFilter[key];
|
||||
cacheFilter[key] = filter;
|
||||
let results = cacheResults[key];
|
||||
if (!oldFilter || filter.indexOf(oldFilter) != 0)
|
||||
results = generate(filter);
|
||||
cacheResults[key] = this[method].apply(this, [results, filter].concat(Array.splice(arguments, 4)));
|
||||
return cacheResults[key];
|
||||
},
|
||||
|
||||
autocommand: function (filter)
|
||||
{
|
||||
let autoCmds = liberator.config.autocommands;
|
||||
@@ -288,12 +301,11 @@ liberator.Completion = function () //{{{
|
||||
|
||||
javascript: function (str)
|
||||
{
|
||||
var matches = str.match(/^(.*?)(\s*\.\s*)?(\w*)$/);
|
||||
var matches = str.match(/^(.*?)((?:\s*\.\s*)?)(\w*)$/);
|
||||
var objects = [];
|
||||
var filter = matches[3] || "";
|
||||
var start = matches[1].length - 1;
|
||||
var offset = matches[1] ? matches[1].length : 0;
|
||||
offset += matches[2] ? matches[2].length : 0;
|
||||
var offset = matches[1].length + matches[2].length;
|
||||
var filter = matches[3];
|
||||
|
||||
if (matches[2])
|
||||
{
|
||||
@@ -338,22 +350,28 @@ liberator.Completion = function () //{{{
|
||||
var completions = [];
|
||||
try
|
||||
{
|
||||
for (let o = 0; o < objects.length; o++)
|
||||
for (let [,object] in Iterator(objects))
|
||||
{
|
||||
completions = completions.concat(eval(
|
||||
"var comp = [];" +
|
||||
"var type = '';" +
|
||||
"var value = '';" +
|
||||
"var obj = eval('with (liberator) {" + objects[o] + "}');" +
|
||||
"for (var i in obj) {" +
|
||||
" try { type = typeof(obj[i]); } catch (e) { type = 'unknown type'; };" +
|
||||
" if (type == 'number' || type == 'string' || type == 'boolean') {" +
|
||||
" value = obj[i];" +
|
||||
" comp.push([[i], type + ': ' + value]); }" +
|
||||
" else {" +
|
||||
" comp.push([[i], type]); }" +
|
||||
"} comp;"
|
||||
));
|
||||
/* Why the double eval? --Kris */
|
||||
completions.push(eval(<![CDATA[
|
||||
let comp = [];
|
||||
let type = "";
|
||||
let value = "";
|
||||
let obj = eval("with (liberator) {" + object + "}");
|
||||
for (let i in obj)
|
||||
{
|
||||
type = "unknown type";
|
||||
try
|
||||
{
|
||||
type = typeof obj[i];
|
||||
}
|
||||
catch (e) {};
|
||||
if (type == "number" || type == "string" || type == "boolean")
|
||||
type += ": " + obj[i];
|
||||
comp.push([[i], type]);
|
||||
}
|
||||
comp;
|
||||
]]>.toString()));
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
@@ -361,7 +379,7 @@ liberator.Completion = function () //{{{
|
||||
completions = [];
|
||||
}
|
||||
|
||||
return [offset, buildLongestStartingSubstring(completions, filter)];
|
||||
return [offset, buildLongestStartingSubstring(liberator.util.flatten(completions), filter)];
|
||||
},
|
||||
|
||||
macro: function (filter)
|
||||
@@ -373,9 +391,11 @@ liberator.Completion = function () //{{{
|
||||
|
||||
search: function (filter)
|
||||
{
|
||||
var keywords = [[k[0], k[1], k[3]] for each (k in liberator.bookmarks.getKeywords())];
|
||||
var engines = liberator.bookmarks.getSearchEngines();
|
||||
return [0, this.filter(engines.concat(keywords), filter, false, true)];
|
||||
let results = this.cached("search", filter,
|
||||
function () Array.concat(liberator.bookmarks.getKeywords().map(function (k) [k[0], k[1], k[3]]),
|
||||
liberator.bookmarks.getSearchEngines()),
|
||||
"filter", false, true);
|
||||
return [0, results];
|
||||
},
|
||||
|
||||
// XXX: Move to bookmarks.js?
|
||||
@@ -466,7 +486,6 @@ liberator.Completion = function () //{{{
|
||||
}
|
||||
|
||||
var cpt = complete || liberator.options["complete"];
|
||||
var autoCompletions = liberator.options["wildoptions"].indexOf("auto") >= 0;
|
||||
var suggestEngineAlias = liberator.options["suggestengines"] || "google";
|
||||
// join all completion arrays together
|
||||
for (let c in liberator.util.arrayIter(cpt))
|
||||
@@ -477,9 +496,9 @@ liberator.Completion = function () //{{{
|
||||
completions.push(this.file(filter, false)[1]);
|
||||
else if (c == "S")
|
||||
completions.push(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
|
||||
else if (c == "b" && !autoCompletions)
|
||||
else if (c == "b")
|
||||
completions.push(liberator.bookmarks.get(filter).map(function (a) [a[0], a[1], a[5]]));
|
||||
else if (c == "h" && !autoCompletions)
|
||||
else if (c == "h")
|
||||
completions.push(liberator.history.get(filter));
|
||||
else if (c == "l") // add completions like Firefox's smart location bar
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ const liberator = (function () //{{{
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
toJavaScriptConsole();
|
||||
Components.utils.reportError(e);
|
||||
liberator.dump(e + "\n");
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ liberator.CommandLine = function () //{{{
|
||||
var wildIndex = 0; // keep track how often we press <Tab> in a row
|
||||
var startHints = false; // whether we're waiting to start hints mode
|
||||
|
||||
var statusTimer = new liberator.util.Timer(51, 100, function ()
|
||||
var statusTimer = new liberator.util.Timer(5, 100, function ()
|
||||
liberator.statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length));
|
||||
var autocompleteTimer = new liberator.util.Timer(50, 100, function (command) {
|
||||
var autocompleteTimer = new liberator.util.Timer(201, 300, function (command) {
|
||||
let res = liberator.completion.ex(command);
|
||||
liberator.commandline.setCompletions(res[1], res[0]);
|
||||
});
|
||||
|
||||
@@ -37,9 +37,9 @@ liberator.util = { //{{{
|
||||
this.notify = function (aTimer)
|
||||
{
|
||||
timer.cancel();
|
||||
this.doneAt = Date.now() + minInterval;
|
||||
this.latest = 0;
|
||||
callback(this.arg);
|
||||
this.doneAt = Date.now() + minInterval;
|
||||
}
|
||||
this.tell = function (arg)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ liberator.util = { //{{{
|
||||
let now = Date.now();
|
||||
if (this.doneAt == -1)
|
||||
timer.cancel();
|
||||
else if (now >= this.doneAt || now >= this.latest)
|
||||
else if (now >= this.doneAt || this.latest && now >= this.latest)
|
||||
return this.notify();
|
||||
|
||||
let timeout = minInterval;
|
||||
|
||||
@@ -107,11 +107,7 @@ function ObjectStore(name, store, data)
|
||||
object = {};
|
||||
};
|
||||
|
||||
this.__iterator__ = function ()
|
||||
{
|
||||
for (let key in object)
|
||||
yield [key, object[key]];
|
||||
};
|
||||
this.__iterator__ = function () Iterator(object);
|
||||
}
|
||||
ObjectStore.prototype = prototype;
|
||||
|
||||
@@ -170,11 +166,7 @@ function ArrayStore(name, store, data)
|
||||
return index >= 0 ? array[index] : array[array.length + index];
|
||||
};
|
||||
|
||||
this.__iterator__ = function ()
|
||||
{
|
||||
for (let i = 0; i < array.length; i++)
|
||||
yield [i, array[i]];
|
||||
};
|
||||
this.__iterator__ = function () Iterator(array);
|
||||
}
|
||||
ArrayStore.prototype = prototype;
|
||||
|
||||
@@ -208,8 +200,7 @@ var storage = {
|
||||
{
|
||||
if (!(key in observers))
|
||||
observers[key] = [];
|
||||
if (observers[key].indexOf(callback) >= 0)
|
||||
return;
|
||||
if (observers[key].indexOf(callback) == -1)
|
||||
observers[key].push(callback);
|
||||
},
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
.liberator-frame-indicator {
|
||||
-moz-binding: url(chrome://vimperator/content/bindings.xml#frame);
|
||||
}
|
||||
|
||||
#liberator-frame-indicator {
|
||||
background-color: red;
|
||||
opacity: 0.5;
|
||||
z-index: 999
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
@@ -26,18 +26,53 @@ the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
/* Applied to all content */
|
||||
.liberator-frame-indicator {
|
||||
-moz-binding: url(chrome://vimperator/content/bindings.xml#frame);
|
||||
}
|
||||
|
||||
#liberator-frame-indicator {
|
||||
background-color: red;
|
||||
opacity: 0.5;
|
||||
z-index: 999
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
/* Applied only to completion buffer and MOW */
|
||||
@-moz-document
|
||||
url-prefix(chrome://vimperator/),
|
||||
url-prefix(chrome://muttator/) {
|
||||
|
||||
*:-moz-loading, *:-moz-broken { display: none !important; }
|
||||
|
||||
.compitem[selected=true] { background-color: yellow; }
|
||||
.compitem .favicon { width: 16px; }
|
||||
.compitem .favicon img { width: 16px; height: 16px; }
|
||||
.compitem .completion { width: 45%; overflow: hidden; }
|
||||
.compitem .description { color: gray; }
|
||||
.compitem > .favicon { width: 16px; }
|
||||
.compitem > .favicon > img { width: 16px; height: 16px; }
|
||||
.compitem > .completion { width: 45%; overflow: hidden; }
|
||||
.compitem > .description { color: gray; }
|
||||
|
||||
.extra-info { color: gray; }
|
||||
|
||||
.times-executed, .time-average { color: green; }
|
||||
.time-total { color: red; }
|
||||
|
||||
.indicator { color: blue; }
|
||||
|
||||
.hl-Number { color: red; }
|
||||
.hl-String { color: green; }
|
||||
.hl-Boolean { color: blue; }
|
||||
.hl-Null { color: blue; }
|
||||
|
||||
.hl-Keyword { color: red; }
|
||||
.hl-Tag { color: blue; }
|
||||
|
||||
}
|
||||
|
||||
/* Applied to completion buffer, MOW, browser window */
|
||||
@-moz-document
|
||||
url-prefix(chrome://vimperator/),
|
||||
url-prefix(chrome://muttator/),
|
||||
|
||||
Reference in New Issue
Block a user