mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-28 21:43:38 +01:00
Speed up file completion a bit, with sorting off. Sort directories first, which slows it down with sorting on.
This commit is contained in:
@@ -327,7 +327,7 @@ CompletionContext.prototype = {
|
|||||||
this.itemCache = {};
|
this.itemCache = {};
|
||||||
this.cache.offset = this.offset;
|
this.cache.offset = this.offset;
|
||||||
if (!this.itemCache[this.key])
|
if (!this.itemCache[this.key])
|
||||||
this.itemCache[this.key] = this._generate.call(this);
|
this.itemCache[this.key] = this._generate.call(this) || [];
|
||||||
return this.itemCache[this.key];
|
return this.itemCache[this.key];
|
||||||
},
|
},
|
||||||
set generate(arg)
|
set generate(arg)
|
||||||
@@ -1384,7 +1384,7 @@ function Completion() //{{{
|
|||||||
io.getRuntimeDirectories("colors").forEach(function (dir) {
|
io.getRuntimeDirectories("colors").forEach(function (dir) {
|
||||||
context.fork(dir.path, 0, null, function (context) {
|
context.fork(dir.path, 0, null, function (context) {
|
||||||
context.filter = dir.path + io.pathSeparator + context.filter;
|
context.filter = dir.path + io.pathSeparator + context.filter;
|
||||||
completion.file(context, true);
|
completion.file(context);
|
||||||
context.title = ["Color Scheme"];
|
context.title = ["Color Scheme"];
|
||||||
context.quote = ["", function (text) text.replace(/\.vimp$/, ""), ""];
|
context.quote = ["", function (text) text.replace(/\.vimp$/, ""), ""];
|
||||||
});
|
});
|
||||||
@@ -1404,10 +1404,10 @@ function Completion() //{{{
|
|||||||
context.completions = config.dialogs;
|
context.completions = config.dialogs;
|
||||||
},
|
},
|
||||||
|
|
||||||
directory: function directory(context, tail)
|
directory: function directory(context, full)
|
||||||
{
|
{
|
||||||
this.file(context, tail);
|
this.file(context, full);
|
||||||
context.filters.push(function (item) this.getKey(item, "description") == "Directory");
|
context.filters.push(function ({ item: f }) f.isDirectory());
|
||||||
},
|
},
|
||||||
|
|
||||||
environment: function environment(context)
|
environment: function environment(context)
|
||||||
@@ -1468,40 +1468,39 @@ function Completion() //{{{
|
|||||||
|
|
||||||
// TODO: support file:// and \ or / path separators on both platforms
|
// TODO: support file:// and \ or / path separators on both platforms
|
||||||
// if "tail" is true, only return names without any directory components
|
// if "tail" is true, only return names without any directory components
|
||||||
file: function file(context, tail)
|
file: function file(context, full)
|
||||||
{
|
{
|
||||||
let [dir] = context.filter.match(/^(?:.*[\/\\])?/);
|
|
||||||
// dir == "" is expanded inside readDirectory to the current dir
|
// dir == "" is expanded inside readDirectory to the current dir
|
||||||
|
let [dir] = context.filter.match(/^(?:.*[\/\\])?/);
|
||||||
|
|
||||||
context.title = ["Path", "Type"];
|
if (!full)
|
||||||
if (tail)
|
|
||||||
context.advance(dir.length);
|
context.advance(dir.length);
|
||||||
context.keys = { text: 0, description: 1, icon: 2 };
|
|
||||||
|
context.title = [full ? "Path" : "Filename", "Type"];
|
||||||
|
context.keys = {
|
||||||
|
text: !full ? "leafName" : function (f) dir + f.leafName,
|
||||||
|
description: function (f) f.isDirectory() ? "Directory" : "File",
|
||||||
|
icon: function (f) f.isDirectory() ? "resource://gre/res/html/folder.png"
|
||||||
|
: "moz-icon://" + f.leafName
|
||||||
|
};
|
||||||
|
context.compare = function ({ item: a }, { item: b })
|
||||||
|
b.isDirectory() - a.isDirectory() || String.localeCompare(a.path, b.path);
|
||||||
|
|
||||||
|
if (options["wildignore"])
|
||||||
|
{
|
||||||
|
let wigRegexp = RegExp("(^" + options.get("wildignore").values.join("|") + ")$");
|
||||||
|
context.filters.push(function ({item: f}) f.isDirectory() || !wigRegexp.test(f.leafName));
|
||||||
|
}
|
||||||
|
|
||||||
// context.background = true;
|
// context.background = true;
|
||||||
context.key = dir;
|
context.key = dir;
|
||||||
context.generate = function generate_file()
|
context.generate = function generate_file()
|
||||||
{
|
{
|
||||||
context.cache.dir = dir;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
let files = io.readDirectory(dir);
|
return io.readDirectory(dir);
|
||||||
|
|
||||||
if (options["wildignore"])
|
|
||||||
{
|
|
||||||
let wigRegexp = RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$");
|
|
||||||
files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName))
|
|
||||||
}
|
|
||||||
|
|
||||||
return files.map(
|
|
||||||
function (file) [tail ? file.leafName : dir + file.leafName,
|
|
||||||
file.isDirectory() ? "Directory" : "File",
|
|
||||||
file.isDirectory() ? "resource://gre/res/html/folder.png"
|
|
||||||
: "moz-icon://" + file.leafName]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
return [];
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -589,8 +589,7 @@ function IO() //{{{
|
|||||||
while (entries.hasMoreElements())
|
while (entries.hasMoreElements())
|
||||||
{
|
{
|
||||||
let entry = entries.getNext();
|
let entry = entries.getNext();
|
||||||
entry.QueryInterface(Ci.nsIFile);
|
array.push(entry.QueryInterface(Ci.nsIFile));
|
||||||
array.push(entry);
|
|
||||||
}
|
}
|
||||||
if (sort)
|
if (sort)
|
||||||
return array.sort(function (a, b) b.isDirectory() - a.isDirectory() || String.localeCompare(a.path, b.path));
|
return array.sort(function (a, b) b.isDirectory() - a.isDirectory() || String.localeCompare(a.path, b.path));
|
||||||
|
|||||||
Reference in New Issue
Block a user