mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 15:22:26 +01:00
Speed up initial file completion a bit by not sorting the results (twice)
This commit is contained in:
@@ -143,11 +143,11 @@ function Bookmarks() //{{{
|
|||||||
};
|
};
|
||||||
|
|
||||||
var observer = {
|
var observer = {
|
||||||
onBeginUpdateBatch: function () {},
|
onBeginUpdateBatch: function onBeginUpdateBatch() {},
|
||||||
onEndUpdateBatch: function () {},
|
onEndUpdateBatch: function onEndUpdateBatch() {},
|
||||||
onItemVisited: function () {},
|
onItemVisited: function onItemVisited() {},
|
||||||
onItemMoved: function () {},
|
onItemMoved: function onItemMoved() {},
|
||||||
onItemAdded: function (itemId, folder, index)
|
onItemAdded: function onItemAdded(itemId, folder, index)
|
||||||
{
|
{
|
||||||
// liberator.dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n");
|
// liberator.dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n");
|
||||||
if (bookmarksService.getItemType(itemId) == bookmarksService.TYPE_BOOKMARK)
|
if (bookmarksService.getItemType(itemId) == bookmarksService.TYPE_BOOKMARK)
|
||||||
@@ -159,13 +159,13 @@ function Bookmarks() //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onItemRemoved: function (itemId, folder, index)
|
onItemRemoved: function onItemRemoved(itemId, folder, index)
|
||||||
{
|
{
|
||||||
// liberator.dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n");
|
// liberator.dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n");
|
||||||
if (deleteBookmark(itemId))
|
if (deleteBookmark(itemId))
|
||||||
storage.fireEvent(name, "remove", itemId);
|
storage.fireEvent(name, "remove", itemId);
|
||||||
},
|
},
|
||||||
onItemChanged: function (itemId, property, isAnnotation, value)
|
onItemChanged: function onItemChanged(itemId, property, isAnnotation, value)
|
||||||
{
|
{
|
||||||
if (isAnnotation)
|
if (isAnnotation)
|
||||||
return;
|
return;
|
||||||
@@ -180,7 +180,7 @@ function Bookmarks() //{{{
|
|||||||
storage.fireEvent(name, "change", itemId);
|
storage.fireEvent(name, "change", itemId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
QueryInterface: function (iid)
|
QueryInterface: function QueryInterface(iid)
|
||||||
{
|
{
|
||||||
if (iid.equals(Components.interfaces.nsINavBookmarkObserver) || iid.equals(Components.interfaces.nsISupports))
|
if (iid.equals(Components.interfaces.nsINavBookmarkObserver) || iid.equals(Components.interfaces.nsISupports))
|
||||||
return this;
|
return this;
|
||||||
@@ -233,8 +233,8 @@ function Bookmarks() //{{{
|
|||||||
"Set the default search engine",
|
"Set the default search engine",
|
||||||
"string", "google",
|
"string", "google",
|
||||||
{
|
{
|
||||||
completer: function (filter) completion.runCompleter("search", filter, true),
|
completer: function completer(filter) completion.runCompleter("search", filter, true),
|
||||||
validator: function (value) completion.runCompleter("search", "", true).some(function ([s]) s == value)
|
validator: function validator(value) completion.runCompleter("search", "", true).some(function ([s]) s == value)
|
||||||
});
|
});
|
||||||
|
|
||||||
options.add(["preload"],
|
options.add(["preload"],
|
||||||
@@ -320,7 +320,7 @@ function Bookmarks() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context, args) completion.bookmark(context, args["-tags"]),
|
completer: function completer(context, args) completion.bookmark(context, args["-tags"]),
|
||||||
options: [[["-tags", "-T"], commands.OPTION_LIST, null, tags]]
|
options: [[["-tags", "-T"], commands.OPTION_LIST, null, tags]]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ function Bookmarks() //{{{
|
|||||||
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
|
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (context) completion.bookmark(context),
|
completer: function completer(context) completion.bookmark(context),
|
||||||
literal: true
|
literal: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ function Bookmarks() //{{{
|
|||||||
// if "bypassCache" is true, it will force a reload of the bookmarks database
|
// if "bypassCache" is true, it will force a reload of the bookmarks database
|
||||||
// on my PC, it takes about 1ms for each bookmark to load, so loading 1000 bookmarks
|
// on my PC, it takes about 1ms for each bookmark to load, so loading 1000 bookmarks
|
||||||
// takes about 1 sec
|
// takes about 1 sec
|
||||||
get: function (filter, tags, bypassCache)
|
get: function get(filter, tags, bypassCache)
|
||||||
{
|
{
|
||||||
if (bypassCache) // Is this really necessary anymore?
|
if (bypassCache) // Is this really necessary anymore?
|
||||||
cache.load();
|
cache.load();
|
||||||
@@ -361,7 +361,7 @@ function Bookmarks() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
|
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
|
||||||
add: function (starOnly, title, url, keyword, tags, force)
|
add: function add(starOnly, title, url, keyword, tags, force)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -400,7 +400,7 @@ function Bookmarks() //{{{
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle: function (url)
|
toggle: function toggle(url)
|
||||||
{
|
{
|
||||||
if (!url)
|
if (!url)
|
||||||
return;
|
return;
|
||||||
@@ -421,7 +421,7 @@ function Bookmarks() //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isBookmarked: function (url)
|
isBookmarked: function isBookmarked(url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -435,7 +435,7 @@ function Bookmarks() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// returns number of deleted bookmarks
|
// returns number of deleted bookmarks
|
||||||
remove: function (url)
|
remove: function remove(url)
|
||||||
{
|
{
|
||||||
if (!url)
|
if (!url)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -462,11 +462,11 @@ function Bookmarks() //{{{
|
|||||||
return count.value;
|
return count.value;
|
||||||
},
|
},
|
||||||
|
|
||||||
getFavicon: function (url) { return getFavicon(url); },
|
getFavicon: function getFavicon(url) { return getFavicon(url); },
|
||||||
|
|
||||||
// TODO: add filtering
|
// TODO: add filtering
|
||||||
// also ensures that each search engine has a Vimperator-friendly alias
|
// also ensures that each search engine has a Vimperator-friendly alias
|
||||||
getSearchEngines: function ()
|
getSearchEngines: function getSearchEngines()
|
||||||
{
|
{
|
||||||
var searchEngines = [];
|
var searchEngines = [];
|
||||||
var firefoxEngines = searchService.getVisibleEngines({});
|
var firefoxEngines = searchService.getVisibleEngines({});
|
||||||
@@ -497,7 +497,7 @@ function Bookmarks() //{{{
|
|||||||
return searchEngines;
|
return searchEngines;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSuggestions: function (engine, query)
|
getSuggestions: function getSuggestions(engine, query)
|
||||||
{
|
{
|
||||||
let ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
let ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
||||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||||
@@ -524,7 +524,7 @@ function Bookmarks() //{{{
|
|||||||
// TODO: add filtering
|
// TODO: add filtering
|
||||||
// format of returned array:
|
// format of returned array:
|
||||||
// [keyword, helptext, url]
|
// [keyword, helptext, url]
|
||||||
getKeywords: function ()
|
getKeywords: function getKeywords()
|
||||||
{
|
{
|
||||||
return cache.keywords;
|
return cache.keywords;
|
||||||
},
|
},
|
||||||
@@ -533,7 +533,7 @@ function Bookmarks() //{{{
|
|||||||
// if @param useDefSearch is true, it uses the default search engine
|
// if @param useDefSearch is true, it uses the default search engine
|
||||||
// @returns the url for the search string
|
// @returns the url for the search string
|
||||||
// if the search also requires a postData, [url, postData] is returned
|
// if the search also requires a postData, [url, postData] is returned
|
||||||
getSearchURL: function (text, useDefsearch)
|
getSearchURL: function getSearchURL(text, useDefsearch)
|
||||||
{
|
{
|
||||||
var url = null;
|
var url = null;
|
||||||
var aPostDataRef = {};
|
var aPostDataRef = {};
|
||||||
@@ -554,7 +554,7 @@ function Bookmarks() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// if openItems is true, open the matching bookmarks items in tabs rather than display
|
// if openItems is true, open the matching bookmarks items in tabs rather than display
|
||||||
list: function (filter, tags, openItems)
|
list: function list(filter, tags, openItems)
|
||||||
{
|
{
|
||||||
if (!openItems)
|
if (!openItems)
|
||||||
return completion.listCompleter("bookmark", filter, tags);
|
return completion.listCompleter("bookmark", filter, tags);
|
||||||
@@ -647,7 +647,7 @@ function History() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context)
|
completer: function completer(context)
|
||||||
{
|
{
|
||||||
let filter = context.filter;
|
let filter = context.filter;
|
||||||
var sh = getWebNavigation().sessionHistory;
|
var sh = getWebNavigation().sessionHistory;
|
||||||
@@ -699,7 +699,7 @@ function History() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context)
|
completer: function completer(context)
|
||||||
{
|
{
|
||||||
let filter = context.filter;
|
let filter = context.filter;
|
||||||
var sh = getWebNavigation().sessionHistory;
|
var sh = getWebNavigation().sessionHistory;
|
||||||
@@ -736,7 +736,7 @@ function History() //{{{
|
|||||||
|
|
||||||
get service() historyService,
|
get service() historyService,
|
||||||
|
|
||||||
get: function (filter, maxItems)
|
get: function get(filter, maxItems)
|
||||||
{
|
{
|
||||||
// no query parameters will get all history
|
// no query parameters will get all history
|
||||||
let query = historyService.getNewQuery();
|
let query = historyService.getNewQuery();
|
||||||
@@ -768,7 +768,7 @@ function History() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// TODO: better names and move to buffer.?
|
// TODO: better names and move to buffer.?
|
||||||
stepTo: function (steps)
|
stepTo: function stepTo(steps)
|
||||||
{
|
{
|
||||||
let index = getWebNavigation().sessionHistory.index + steps;
|
let index = getWebNavigation().sessionHistory.index + steps;
|
||||||
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
|
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
|
||||||
@@ -777,7 +777,7 @@ function History() //{{{
|
|||||||
liberator.beep();
|
liberator.beep();
|
||||||
},
|
},
|
||||||
|
|
||||||
goToStart: function ()
|
goToStart: function goToStart()
|
||||||
{
|
{
|
||||||
let index = getWebNavigation().sessionHistory.index;
|
let index = getWebNavigation().sessionHistory.index;
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
@@ -786,7 +786,7 @@ function History() //{{{
|
|||||||
getWebNavigation().gotoIndex(0);
|
getWebNavigation().gotoIndex(0);
|
||||||
},
|
},
|
||||||
|
|
||||||
goToEnd: function ()
|
goToEnd: function goToEnd()
|
||||||
{
|
{
|
||||||
let index = getWebNavigation().sessionHistory.index;
|
let index = getWebNavigation().sessionHistory.index;
|
||||||
if (index == getWebNavigation().sessionHistory.count - 1)
|
if (index == getWebNavigation().sessionHistory.count - 1)
|
||||||
@@ -796,7 +796,7 @@ function History() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// if openItems is true, open the matching history items in tabs rather than display
|
// if openItems is true, open the matching history items in tabs rather than display
|
||||||
list: function (filter, openItems)
|
list: function list(filter, openItems)
|
||||||
{
|
{
|
||||||
if (!openItems)
|
if (!openItems)
|
||||||
return completion.listCompleter("history", filter);
|
return completion.listCompleter("history", filter);
|
||||||
@@ -922,13 +922,13 @@ function QuickMarks() //{{{
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
add: function (qmark, location)
|
add: function add(qmark, location)
|
||||||
{
|
{
|
||||||
qmarks.set(qmark, location);
|
qmarks.set(qmark, location);
|
||||||
liberator.echo("Added Quick Mark '" + qmark + "': " + location);
|
liberator.echo("Added Quick Mark '" + qmark + "': " + location);
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function (filter)
|
remove: function remove(filter)
|
||||||
{
|
{
|
||||||
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
||||||
|
|
||||||
@@ -939,12 +939,12 @@ function QuickMarks() //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAll: function ()
|
removeAll: function removeAll()
|
||||||
{
|
{
|
||||||
qmarks.clear();
|
qmarks.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
jumpTo: function (qmark, where)
|
jumpTo: function jumpTo(qmark, where)
|
||||||
{
|
{
|
||||||
var url = qmarks.get(qmark);
|
var url = qmarks.get(qmark);
|
||||||
|
|
||||||
@@ -954,7 +954,7 @@ function QuickMarks() //{{{
|
|||||||
liberator.echoerr("E20: QuickMark not set");
|
liberator.echoerr("E20: QuickMark not set");
|
||||||
},
|
},
|
||||||
|
|
||||||
list: function (filter)
|
list: function list(filter)
|
||||||
{
|
{
|
||||||
var marks = [key for ([key, val] in qmarks)];
|
var marks = [key for ([key, val] in qmarks)];
|
||||||
// This was a lot nicer without the lambda...
|
// This was a lot nicer without the lambda...
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ CompletionContext.prototype = {
|
|||||||
if (!context.hasItems)
|
if (!context.hasItems)
|
||||||
return [];
|
return [];
|
||||||
let prefix = self.value.substring(minStart, context.offset);
|
let prefix = self.value.substring(minStart, context.offset);
|
||||||
return [{ text: prefix + item.text, item: item.item } for ([i, item] in Iterator(context.items))];
|
return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item }));
|
||||||
|
//return [{ text: prefix + item.text, item: item.item } for ([i, item] in Iterator(context.items))];
|
||||||
});
|
});
|
||||||
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring }
|
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring }
|
||||||
},
|
},
|
||||||
@@ -329,7 +330,7 @@ CompletionContext.prototype = {
|
|||||||
this._filter = this._filter.substr(count);
|
this._filter = this._filter.substr(count);
|
||||||
},
|
},
|
||||||
|
|
||||||
getItems: function (start, end)
|
getItems: function getItems(start, end)
|
||||||
{
|
{
|
||||||
let self = this;
|
let self = this;
|
||||||
let items = this.items;
|
let items = this.items;
|
||||||
@@ -339,7 +340,7 @@ CompletionContext.prototype = {
|
|||||||
return util.map(util.range(start, end, reverse), function (i) items[i]);
|
return util.map(util.range(start, end, reverse), function (i) items[i]);
|
||||||
},
|
},
|
||||||
|
|
||||||
getRows: function (start, end, doc)
|
getRows: function getRows(start, end, doc)
|
||||||
{
|
{
|
||||||
let self = this;
|
let self = this;
|
||||||
let items = this.items;
|
let items = this.items;
|
||||||
@@ -362,7 +363,7 @@ CompletionContext.prototype = {
|
|||||||
return context;
|
return context;
|
||||||
},
|
},
|
||||||
|
|
||||||
getText: function (item)
|
getText: function getText(item)
|
||||||
{
|
{
|
||||||
let text = item[self.keys["text"]];
|
let text = item[self.keys["text"]];
|
||||||
if (self.quote)
|
if (self.quote)
|
||||||
@@ -392,7 +393,7 @@ CompletionContext.prototype = {
|
|||||||
catch (e) {}
|
catch (e) {}
|
||||||
},
|
},
|
||||||
|
|
||||||
match: function (str)
|
match: function match(str)
|
||||||
{
|
{
|
||||||
let filter = this.filter;
|
let filter = this.filter;
|
||||||
if (this.ignoreCase)
|
if (this.ignoreCase)
|
||||||
@@ -955,7 +956,7 @@ function Completion() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
_runCompleter: function (name, filter)
|
_runCompleter: function _runCompleter(name, filter)
|
||||||
{
|
{
|
||||||
let context = CompletionContext(filter);
|
let context = CompletionContext(filter);
|
||||||
if (typeof name == "string")
|
if (typeof name == "string")
|
||||||
@@ -966,7 +967,7 @@ function Completion() //{{{
|
|||||||
return context.allItems;
|
return context.allItems;
|
||||||
},
|
},
|
||||||
|
|
||||||
runCompleter: function (name, filter)
|
runCompleter: function runCompleter(name, filter)
|
||||||
{
|
{
|
||||||
return this._runCompleter(name, filter).items.map(function (i) i.item);
|
return this._runCompleter(name, filter).items.map(function (i) i.item);
|
||||||
},
|
},
|
||||||
@@ -1059,7 +1060,7 @@ function Completion() //{{{
|
|||||||
return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1);
|
return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1);
|
||||||
},
|
},
|
||||||
|
|
||||||
listCompleter: function (name, filter)
|
listCompleter: function listCompleter(name, filter)
|
||||||
{
|
{
|
||||||
let context = CompletionContext(filter || "");
|
let context = CompletionContext(filter || "");
|
||||||
context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 2)));
|
context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 2)));
|
||||||
@@ -1230,13 +1231,13 @@ function Completion() //{{{
|
|||||||
context.keys = { text: 0, description: 1, icon: 2 };
|
context.keys = { text: 0, description: 1, icon: 2 };
|
||||||
context.anchored = true;
|
context.anchored = true;
|
||||||
context.key = dir;
|
context.key = dir;
|
||||||
context.generate = function generate()
|
context.generate = function generate_file()
|
||||||
{
|
{
|
||||||
context.cache.dir = dir;
|
context.cache.dir = dir;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
let files = io.readDirectory(dir, true);
|
let files = io.readDirectory(dir);
|
||||||
|
|
||||||
if (options["wildignore"])
|
if (options["wildignore"])
|
||||||
{
|
{
|
||||||
@@ -1273,7 +1274,7 @@ function Completion() //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
history: function (context)
|
history: function history(context)
|
||||||
{
|
{
|
||||||
context.format = history.format;
|
context.format = history.format;
|
||||||
context.title = ["History"]
|
context.title = ["History"]
|
||||||
@@ -1287,7 +1288,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
javascript: function _javascript(context) javascript.complete(context),
|
javascript: function _javascript(context) javascript.complete(context),
|
||||||
|
|
||||||
location: function (context)
|
location: function location(context)
|
||||||
{
|
{
|
||||||
if (!completionService)
|
if (!completionService)
|
||||||
return
|
return
|
||||||
@@ -1303,7 +1304,6 @@ function Completion() //{{{
|
|||||||
for (i in util.range(0, result.matchCount))
|
for (i in util.range(0, result.matchCount))
|
||||||
];
|
];
|
||||||
context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
|
context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
|
||||||
let filter = context.filter;
|
|
||||||
});
|
});
|
||||||
completionService.stopSearch();
|
completionService.stopSearch();
|
||||||
completionService.startSearch(context.filter, "", context.result, {
|
completionService.startSearch(context.filter, "", context.result, {
|
||||||
@@ -1468,7 +1468,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
urlCompleters: {},
|
urlCompleters: {},
|
||||||
|
|
||||||
addUrlCompleter: function (opt)
|
addUrlCompleter: function addUrlCompleter(opt)
|
||||||
{
|
{
|
||||||
this.urlCompleters[opt] = UrlCompleter.apply(null, Array.slice(arguments));
|
this.urlCompleters[opt] = UrlCompleter.apply(null, Array.slice(arguments));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const util = { //{{{
|
|||||||
Array: {
|
Array: {
|
||||||
// [["a", "b"], ["c", "d"]] -> {a: "b", c: "d"}
|
// [["a", "b"], ["c", "d"]] -> {a: "b", c: "d"}
|
||||||
// From Common Lisp, more or less
|
// From Common Lisp, more or less
|
||||||
assocToObj: function (assoc)
|
assocToObj: function assocToObj(assoc)
|
||||||
{
|
{
|
||||||
let obj = {};
|
let obj = {};
|
||||||
assoc.forEach(function ([k, v]) { obj[k] = v });
|
assoc.forEach(function ([k, v]) { obj[k] = v });
|
||||||
@@ -43,9 +43,9 @@ const util = { //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// flatten an array: [["foo", ["bar"]], ["baz"], "quux"] -> ["foo", ["bar"], "baz", "quux"]
|
// flatten an array: [["foo", ["bar"]], ["baz"], "quux"] -> ["foo", ["bar"], "baz", "quux"]
|
||||||
flatten: function (ary) Array.concat.apply([], ary),
|
flatten: function flatten(ary) Array.concat.apply([], ary),
|
||||||
|
|
||||||
iterator: function (ary)
|
iterator: function iterator(ary)
|
||||||
{
|
{
|
||||||
let length = ary.length;
|
let length = ary.length;
|
||||||
for (let i = 0; i < length; i++)
|
for (let i = 0; i < length; i++)
|
||||||
@@ -59,7 +59,7 @@ const util = { //{{{
|
|||||||
yield [i, ary[i]];
|
yield [i, ary[i]];
|
||||||
},
|
},
|
||||||
|
|
||||||
uniq: function (ary, unsorted)
|
uniq: function uniq(ary, unsorted)
|
||||||
{
|
{
|
||||||
let ret = [];
|
let ret = [];
|
||||||
if (unsorted)
|
if (unsorted)
|
||||||
@@ -136,7 +136,7 @@ const util = { //{{{
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
cloneObject: function (obj)
|
cloneObject: function cloneObject(obj)
|
||||||
{
|
{
|
||||||
let newObj = {};
|
let newObj = {};
|
||||||
for (let [k, v] in Iterator(obj))
|
for (let [k, v] in Iterator(obj))
|
||||||
@@ -144,21 +144,21 @@ const util = { //{{{
|
|||||||
return newObj;
|
return newObj;
|
||||||
},
|
},
|
||||||
|
|
||||||
clip: function (str, length)
|
clip: function clip(str, length)
|
||||||
{
|
{
|
||||||
return str.length <= length ? str : str.substr(0, length - 3) + "...";
|
return str.length <= length ? str : str.substr(0, length - 3) + "...";
|
||||||
},
|
},
|
||||||
|
|
||||||
compareIgnoreCase: function (a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()),
|
compareIgnoreCase: function compareIgnoreCase(a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()),
|
||||||
|
|
||||||
computedStyle: function (node)
|
computedStyle: function computedStyle(node)
|
||||||
{
|
{
|
||||||
while (node instanceof Text && node.parentNode)
|
while (node instanceof Text && node.parentNode)
|
||||||
node = node.parentNode;
|
node = node.parentNode;
|
||||||
return node.ownerDocument.defaultView.getComputedStyle(node, null);
|
return node.ownerDocument.defaultView.getComputedStyle(node, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
copyToClipboard: function (str, verbose)
|
copyToClipboard: function copyToClipboard(str, verbose)
|
||||||
{
|
{
|
||||||
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
||||||
.getService(Components.interfaces.nsIClipboardHelper);
|
.getService(Components.interfaces.nsIClipboardHelper);
|
||||||
@@ -168,14 +168,14 @@ const util = { //{{{
|
|||||||
liberator.echo("Yanked " + str, commandline.FORCE_SINGLELINE);
|
liberator.echo("Yanked " + str, commandline.FORCE_SINGLELINE);
|
||||||
},
|
},
|
||||||
|
|
||||||
createURI: function (str)
|
createURI: function createURI(str)
|
||||||
{
|
{
|
||||||
const fixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
const fixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||||
.getService(Components.interfaces.nsIURIFixup);
|
.getService(Components.interfaces.nsIURIFixup);
|
||||||
return fixup.createFixupURI(str, fixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP);
|
return fixup.createFixupURI(str, fixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP);
|
||||||
},
|
},
|
||||||
|
|
||||||
escapeHTML: function (str)
|
escapeHTML: function escapeHTML(str)
|
||||||
{
|
{
|
||||||
// XXX: the following code is _much_ slower than a simple .replace()
|
// XXX: the following code is _much_ slower than a simple .replace()
|
||||||
// :history display went down from 2 to 1 second after changing
|
// :history display went down from 2 to 1 second after changing
|
||||||
@@ -186,19 +186,19 @@ const util = { //{{{
|
|||||||
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
},
|
},
|
||||||
|
|
||||||
escapeRegex: function (str)
|
escapeRegex: function escapeRegex(str)
|
||||||
{
|
{
|
||||||
return str.replace(/([\\{}()[\].?*+])/g, "\\$1");
|
return str.replace(/([\\{}()[\].?*+])/g, "\\$1");
|
||||||
},
|
},
|
||||||
|
|
||||||
escapeString: function (str, delimiter)
|
escapeString: function escapeString(str, delimiter)
|
||||||
{
|
{
|
||||||
if (delimiter == undefined)
|
if (delimiter == undefined)
|
||||||
delimiter = '"';
|
delimiter = '"';
|
||||||
return delimiter + str.replace(/([\\'"])/g, "\\$1").replace("\n", "\\n", "g").replace("\t", "\\t", "g") + delimiter;
|
return delimiter + str.replace(/([\\'"])/g, "\\$1").replace("\n", "\\n", "g").replace("\t", "\\t", "g") + delimiter;
|
||||||
},
|
},
|
||||||
|
|
||||||
formatBytes: function (num, decimalPlaces, humanReadable)
|
formatBytes: function formatBytes(num, decimalPlaces, humanReadable)
|
||||||
{
|
{
|
||||||
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
||||||
let unitIndex = 0;
|
let unitIndex = 0;
|
||||||
@@ -234,7 +234,7 @@ const util = { //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// generates an Asciidoc help entry, "command" can also be a mapping
|
// generates an Asciidoc help entry, "command" can also be a mapping
|
||||||
generateHelp: function (command, extraHelp)
|
generateHelp: function generateHelp(command, extraHelp)
|
||||||
{
|
{
|
||||||
let start = "", end = "";
|
let start = "", end = "";
|
||||||
if (command instanceof liberator.Command)
|
if (command instanceof liberator.Command)
|
||||||
@@ -285,7 +285,7 @@ const util = { //{{{
|
|||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
|
||||||
httpGet: function (url)
|
httpGet: function httpGet(url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -300,9 +300,9 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
identity: function (k) k,
|
identity: function identity(k) k,
|
||||||
|
|
||||||
map: function (obj, fn)
|
map: function map(obj, fn)
|
||||||
{
|
{
|
||||||
let ary = [];
|
let ary = [];
|
||||||
for (let i in Iterator(obj))
|
for (let i in Iterator(obj))
|
||||||
@@ -311,7 +311,7 @@ const util = { //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// if color = true it uses HTML markup to color certain items
|
// if color = true it uses HTML markup to color certain items
|
||||||
objectToString: function (object, color)
|
objectToString: function objectToString(object, color)
|
||||||
{
|
{
|
||||||
/* Use E4X literals so html is automatically quoted
|
/* Use E4X literals so html is automatically quoted
|
||||||
* only when it's asked for. Noone wants to see <
|
* only when it's asked for. Noone wants to see <
|
||||||
@@ -380,7 +380,7 @@ const util = { //{{{
|
|||||||
return color ? string : [s for each (s in string)].join("");
|
return color ? string : [s for each (s in string)].join("");
|
||||||
},
|
},
|
||||||
|
|
||||||
range: function (start, end, reverse)
|
range: function range(start, end, reverse)
|
||||||
{
|
{
|
||||||
if (!reverse)
|
if (!reverse)
|
||||||
{
|
{
|
||||||
@@ -394,7 +394,7 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
interruptableRange: function (start, end, time)
|
interruptableRange: function interruptableRange(start, end, time)
|
||||||
{
|
{
|
||||||
let endTime = Date.now() + time;
|
let endTime = Date.now() + time;
|
||||||
while (start < end)
|
while (start < end)
|
||||||
@@ -409,7 +409,7 @@ const util = { //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
|
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
|
||||||
readFromClipboard: function ()
|
readFromClipboard: function readFromClipboard()
|
||||||
{
|
{
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
@@ -445,7 +445,7 @@ const util = { //{{{
|
|||||||
|
|
||||||
// takes a string like 'google bla, www.osnews.com'
|
// takes a string like 'google bla, www.osnews.com'
|
||||||
// and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
|
// and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
|
||||||
stringToURLArray: function (str)
|
stringToURLArray: function stringToURLArray(str)
|
||||||
{
|
{
|
||||||
let urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*"));
|
let urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*"));
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ const util = { //{{{
|
|||||||
return urls;
|
return urls;
|
||||||
},
|
},
|
||||||
|
|
||||||
xmlToDom: function (node, doc, nodes)
|
xmlToDom: function xmlToDom(node, doc, nodes)
|
||||||
{
|
{
|
||||||
XML.prettyPrinting = false;
|
XML.prettyPrinting = false;
|
||||||
switch (node.nodeKind())
|
switch (node.nodeKind())
|
||||||
@@ -565,7 +565,7 @@ function Struct()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Struct.prototype = {
|
Struct.prototype = {
|
||||||
clone: function ()
|
clone: function clone()
|
||||||
{
|
{
|
||||||
return this.constructor.apply(null, this.slice());
|
return this.constructor.apply(null, this.slice());
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user