mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 14:27:58 +01:00
* io.getFile() works for relative filenames now
* completion functions must return the start point now from which position of the "filter" string they return the results
This commit is contained in:
@@ -260,7 +260,7 @@ vimperator.Buffer = function () //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var items = vimperator.completion.buffer("");
|
var items = vimperator.completion.buffers("")[1];
|
||||||
vimperator.bufferwindow.show(items);
|
vimperator.bufferwindow.show(items);
|
||||||
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ vimperator.Buffer = function () //{{{
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: move this to vimperator.buffers.get()
|
// TODO: move this to vimperator.buffers.get()
|
||||||
var items = vimperator.completion.buffer("");
|
var items = vimperator.completion.buffers("")[1];
|
||||||
var number, indicator, title, url;
|
var number, indicator, title, url;
|
||||||
|
|
||||||
var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" + "<table>";
|
var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" + "<table>";
|
||||||
@@ -451,7 +451,7 @@ vimperator.Buffer = function () //{{{
|
|||||||
if (!vimperator.bufferwindow.visible())
|
if (!vimperator.bufferwindow.visible())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var items = vimperator.completion.buffer("");
|
var items = vimperator.completion.buffers("")[1];
|
||||||
vimperator.bufferwindow.show(items);
|
vimperator.bufferwindow.show(items);
|
||||||
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ vimperator.Commands = function () //{{{
|
|||||||
if (vimperator.completion.match([url, title], filter, false))
|
if (vimperator.completion.match([url, title], filter, false))
|
||||||
completions.push([url, title]);
|
completions.push([url, title]);
|
||||||
}
|
}
|
||||||
return completions;
|
return [0, completions];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -639,7 +639,7 @@ vimperator.Commands = function () //{{{
|
|||||||
"The special version <code class=\"command\">:bmarks!</code> opens the default Firefox bookmarks window.<br/>" +
|
"The special version <code class=\"command\">:bmarks!</code> opens the default Firefox bookmarks window.<br/>" +
|
||||||
"Filter can also contain the following options:<br/>" +
|
"Filter can also contain the following options:<br/>" +
|
||||||
"-tags=comma,separated,tag,list<br/>",
|
"-tags=comma,separated,tag,list<br/>",
|
||||||
completer: function (filter) { return vimperator.bookmarks.get(filter); },
|
completer: function (filter) { return [0, vimperator.bookmarks.get(filter)]; },
|
||||||
args: [[["-tags", "-T"], OPTION_LIST]]
|
args: [[["-tags", "-T"], OPTION_LIST]]
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -653,7 +653,7 @@ vimperator.Commands = function () //{{{
|
|||||||
"it is selected. With <code class=\"argument\">[!]</code> the next buffer matching the argument " +
|
"it is selected. With <code class=\"argument\">[!]</code> the next buffer matching the argument " +
|
||||||
"is selected, even if it cannot be identified uniquely.<br/>" +
|
"is selected, even if it cannot be identified uniquely.<br/>" +
|
||||||
"Use <code class=\"mapping\">b</code> as a shortcut to open this prompt.",
|
"Use <code class=\"mapping\">b</code> as a shortcut to open this prompt.",
|
||||||
completer: function (filter) { return vimperator.completion.buffer(filter); }
|
completer: function (filter) { return vimperator.completion.buffers(filter); }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
commandManager.add(new vimperator.Command(["dia[log]"],
|
commandManager.add(new vimperator.Command(["dia[log]"],
|
||||||
@@ -684,8 +684,8 @@ vimperator.Commands = function () //{{{
|
|||||||
case "savepage": saveDocument(window.content.document); break;
|
case "savepage": saveDocument(window.content.document); break;
|
||||||
case "searchengines": openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); break;
|
case "searchengines": openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); break;
|
||||||
// TODO add viewPartialSource('selection'); ...
|
// TODO add viewPartialSource('selection'); ...
|
||||||
case "": vimperator.echoerr("E474: Invalid Argument"); break;
|
case "": vimperator.echoerr("E474: Invalid argument"); break;
|
||||||
default: vimperator.echoerr("Dialog: '" + args + "' is not available");
|
default: vimperator.echoerr("Dialog '" + args + "' is not available");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -731,7 +731,7 @@ vimperator.Commands = function () //{{{
|
|||||||
"Use <code><Tab></code> key on a string to complete the URL which you want to delete.<br/>" +
|
"Use <code><Tab></code> key on a string to complete the URL which you want to delete.<br/>" +
|
||||||
"The following options WILL be interpreted in the future:<br/>" +
|
"The following options WILL be interpreted in the future:<br/>" +
|
||||||
" [!] a special version to delete ALL bookmarks <br/>",
|
" [!] a special version to delete ALL bookmarks <br/>",
|
||||||
completer: function (filter) { return vimperator.bookmarks.get(filter); }
|
completer: function (filter) { return [0, vimperator.bookmarks.get(filter)]; }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
commandManager.add(new vimperator.Command(["com[mand]"],
|
commandManager.add(new vimperator.Command(["com[mand]"],
|
||||||
@@ -964,7 +964,7 @@ vimperator.Commands = function () //{{{
|
|||||||
if (vimperator.completion.match([url, title], filter, false))
|
if (vimperator.completion.match([url, title], filter, false))
|
||||||
completions.push([url, title]);
|
completions.push([url, title]);
|
||||||
}
|
}
|
||||||
return completions;
|
return [0, completions];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -998,7 +998,7 @@ vimperator.Commands = function () //{{{
|
|||||||
shortHelp: "Show recently visited URLs",
|
shortHelp: "Show recently visited URLs",
|
||||||
help: "Open the message window at the bottom of the screen with all history items which match <code class=\"argument\">[filter]</code> either in the title or URL.<br/>" +
|
help: "Open the message window at the bottom of the screen with all history items which match <code class=\"argument\">[filter]</code> either in the title or URL.<br/>" +
|
||||||
"The special version <code class=\"command\">:history!</code> opens the default Firefox history window.",
|
"The special version <code class=\"command\">:history!</code> opens the default Firefox history window.",
|
||||||
completer: function (filter) { return vimperator.history.get(filter); }
|
completer: function (filter) { return [0, vimperator.history.get(filter)]; }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
commandManager.add(new vimperator.Command(["javas[cript]", "js"],
|
commandManager.add(new vimperator.Command(["javas[cript]", "js"],
|
||||||
@@ -1856,7 +1856,7 @@ vimperator.Commands = function () //{{{
|
|||||||
"<code class=\"command\">:set option+={value}</code>, <code class=\"command\">:set option^={value}</code> and <code class=\"command\">:set option-={value}</code> " +
|
"<code class=\"command\">:set option+={value}</code>, <code class=\"command\">:set option^={value}</code> and <code class=\"command\">:set option-={value}</code> " +
|
||||||
"adds/multiplies/subtracts <code class=\"argument\">{value}</code> from a number option and appends/prepends/removes <code class=\"argument\">{value}</code> from a string option.<br/>" +
|
"adds/multiplies/subtracts <code class=\"argument\">{value}</code> from a number option and appends/prepends/removes <code class=\"argument\">{value}</code> from a string option.<br/>" +
|
||||||
"<code class=\"command\">:set all</code> shows the current value of all options and <code class=\"command\">:set all&</code> resets all options to their default values.<br/>",
|
"<code class=\"command\">:set all</code> shows the current value of all options and <code class=\"command\">:set all&</code> resets all options to their default values.<br/>",
|
||||||
completer: function (filter) { return vimperator.completion.option(filter); }
|
completer: function (filter) { return vimperator.completion.options(filter); }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
// TODO: sclose instead?
|
// TODO: sclose instead?
|
||||||
@@ -1937,7 +1937,7 @@ vimperator.Commands = function () //{{{
|
|||||||
"The .vimperatorrc file in your home directory and any files in ~/.vimperator/plugin/ are always sourced at startup.<br/>" +
|
"The .vimperatorrc file in your home directory and any files in ~/.vimperator/plugin/ are always sourced at startup.<br/>" +
|
||||||
"~ is supported as a shortcut for the <var>$HOME</var> directory.<br/>" +
|
"~ is supported as a shortcut for the <var>$HOME</var> directory.<br/>" +
|
||||||
"If <code class=\"command\">!</code> is specified, errors are not printed.",
|
"If <code class=\"command\">!</code> is specified, errors are not printed.",
|
||||||
completer: function (filter) { return vimperator.completion.file(filter); }
|
completer: function (filter) { return vimperator.completion.file(filter, true); }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
commandManager.add(new vimperator.Command(["st[op]"],
|
commandManager.add(new vimperator.Command(["st[op]"],
|
||||||
@@ -1955,7 +1955,7 @@ vimperator.Commands = function () //{{{
|
|||||||
help: "Works only for commands that support it, currently:" +
|
help: "Works only for commands that support it, currently:" +
|
||||||
"<ul><li>:tab help</li>" +
|
"<ul><li>:tab help</li>" +
|
||||||
"<li>:tab prefs[!]</li></ul>",
|
"<li>:tab prefs[!]</li></ul>",
|
||||||
completer: function (filter) { return vimperator.completion.command(filter); }
|
completer: function (filter) { return vimperator.completion.commands(filter); }
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
commandManager.add(new vimperator.Command(["tabl[ast]"],
|
commandManager.add(new vimperator.Command(["tabl[ast]"],
|
||||||
@@ -2181,7 +2181,7 @@ vimperator.Commands = function () //{{{
|
|||||||
if (vimperator.completion.match([url, title], filter, false))
|
if (vimperator.completion.match([url, title], filter, false))
|
||||||
completions.push([url, title]);
|
completions.push([url, title]);
|
||||||
}
|
}
|
||||||
return completions;
|
return [0, completions];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -153,21 +153,22 @@ vimperator.Completion = function () //{{{
|
|||||||
["print", "Show print dialog"],
|
["print", "Show print dialog"],
|
||||||
["saveframe", "Save frame to disk"],
|
["saveframe", "Save frame to disk"],
|
||||||
["savepage", "Save page to disk"],
|
["savepage", "Save page to disk"],
|
||||||
["searchengines", "Manage installed search engines"]]
|
["searchengines", "Manage installed search engines"]
|
||||||
|
];
|
||||||
|
|
||||||
if (!filter)
|
if (!filter)
|
||||||
return nodes;
|
return [0, nodes];
|
||||||
|
|
||||||
var mapped = nodes.map(function (node) {
|
var mapped = nodes.map(function (node) {
|
||||||
return [[node[0]], node[1]];
|
return [[node[0]], node[1]];
|
||||||
});
|
});
|
||||||
|
|
||||||
return buildLongestCommonSubstring(mapped, filter);
|
return [0, buildLongestCommonSubstring(mapped, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
// filter a list of urls
|
// filter a list of urls
|
||||||
//
|
//
|
||||||
// may consist of searchengines, filenames, bookmarks and history,
|
// may consist of search engines, filenames, bookmarks and history,
|
||||||
// depending on the 'complete' option
|
// depending on the 'complete' option
|
||||||
// if the 'complete' argument is passed like "h", it temporarily overrides the complete option
|
// if the 'complete' argument is passed like "h", it temporarily overrides the complete option
|
||||||
url: function (filter, complete)
|
url: function (filter, complete)
|
||||||
@@ -175,58 +176,68 @@ vimperator.Completion = function () //{{{
|
|||||||
var completions = [];
|
var completions = [];
|
||||||
substrings = [];
|
substrings = [];
|
||||||
|
|
||||||
|
var start = 0;
|
||||||
|
var skip = filter.match(/^(.*,\s+)(.*)/); // start after the last ", "
|
||||||
|
if (skip)
|
||||||
|
{
|
||||||
|
start += skip[1].length;
|
||||||
|
filter = skip[2];
|
||||||
|
}
|
||||||
|
|
||||||
var cpt = complete || vimperator.options["complete"];
|
var cpt = complete || vimperator.options["complete"];
|
||||||
// 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++)
|
||||||
{
|
{
|
||||||
if (cpt[i] == "s")
|
if (cpt[i] == "s")
|
||||||
completions = completions.concat(this.search(filter));
|
completions = completions.concat(this.search(filter)[1]);
|
||||||
else if (cpt[i] == "b")
|
else if (cpt[i] == "b")
|
||||||
completions = completions.concat(vimperator.bookmarks.get(filter));
|
completions = completions.concat(vimperator.bookmarks.get(filter));
|
||||||
else if (cpt[i] == "h")
|
else if (cpt[i] == "h")
|
||||||
completions = completions.concat(vimperator.history.get(filter));
|
completions = completions.concat(vimperator.history.get(filter));
|
||||||
else if (cpt[i] == "f")
|
else if (cpt[i] == "f")
|
||||||
completions = completions.concat(this.file(filter, true));
|
completions = completions.concat(this.file(filter, false)[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions;
|
return [start, completions];
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function (filter)
|
search: function (filter)
|
||||||
{
|
{
|
||||||
var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords());
|
var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords());
|
||||||
|
|
||||||
if (!filter) return engines.map(function (engine) {
|
if (!filter)
|
||||||
return [engine[0], engine[1]];
|
return [0, engines];
|
||||||
});
|
|
||||||
var mapped = engines.map(function (engine) {
|
var mapped = engines.map(function (engine) {
|
||||||
return [[engine[0]], engine[1]];
|
return [[engine[0]], engine[1]];
|
||||||
});
|
});
|
||||||
return buildLongestCommonSubstring(mapped, filter);
|
return [0, buildLongestCommonSubstring(mapped, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: support file:// and \ or / path separators on both platforms
|
// TODO: support file:// and \ or / path separators on both platforms
|
||||||
file: function (filter)
|
// TODO: sort directories first
|
||||||
|
// if "short" is true, only return names without any directory components
|
||||||
|
file: function (filter, short)
|
||||||
{
|
{
|
||||||
// this is now also used as part of the url completion, so the
|
// this is now also used as part of the url completion, so the
|
||||||
// substrings shouldn't be cleared for that case
|
// substrings shouldn't be cleared for that case
|
||||||
if (!arguments[1])
|
if (!arguments[1])
|
||||||
substrings = [];
|
substrings = [];
|
||||||
|
|
||||||
var matches = filter.match(/^(.*[\/\\])(.*?)$/);
|
var dir = "", compl = "";
|
||||||
var dir;
|
var matches = filter.match(/^(.*[\/\\])?(.*?)$/);
|
||||||
|
if (matches)
|
||||||
if (!matches || !(dir = matches[1]))
|
{
|
||||||
return [];
|
dir = matches[1] || ""; // "" is expanded inside readDirectory to the current dir
|
||||||
|
compl = matches[2] || "";
|
||||||
var compl = matches[2] || "";
|
}
|
||||||
|
|
||||||
var files = [], mapped = [];
|
var files = [], mapped = [];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
files = vimperator.io.readDirectory(dir);
|
files = vimperator.io.readDirectory(dir);
|
||||||
mapped = files.map(function (file) {
|
mapped = files.map(function (file) {
|
||||||
return [[file.path], file.isDirectory() ? "Directory" : "File"];
|
return [[short ? file.leafName : dir + file.leafName], file.isDirectory() ? "Directory" : "File"];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -234,8 +245,7 @@ vimperator.Completion = function () //{{{
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [short ? dir.length : 0, buildLongestStartingSubstring(mapped, compl)];
|
||||||
return buildLongestStartingSubstring(mapped, filter);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
help: function (filter)
|
help: function (filter)
|
||||||
@@ -248,7 +258,7 @@ vimperator.Completion = function () //{{{
|
|||||||
substrings = [];
|
substrings = [];
|
||||||
for (var command in vimperator.commands)
|
for (var command in vimperator.commands)
|
||||||
helpArray.push([command.longNames.map(function ($_) { return ":" + $_; }), command.shortHelp]);
|
helpArray.push([command.longNames.map(function ($_) { return ":" + $_; }), command.shortHelp]);
|
||||||
options = this.option(filter, true);
|
options = this.options(filter, true);
|
||||||
helpArray = helpArray.concat(options.map(function ($_) {
|
helpArray = helpArray.concat(options.map(function ($_) {
|
||||||
return [
|
return [
|
||||||
$_[0].map(function ($_) { return "'" + $_ + "'"; }),
|
$_[0].map(function ($_) { return "'" + $_ + "'"; }),
|
||||||
@@ -258,14 +268,14 @@ vimperator.Completion = function () //{{{
|
|||||||
for (var map in vimperator.mappings)
|
for (var map in vimperator.mappings)
|
||||||
helpArray.push([map.names, map.shortHelp]);
|
helpArray.push([map.names, map.shortHelp]);
|
||||||
|
|
||||||
if (!filter) return helpArray.map(function ($_) {
|
// unfiltered, use the first command
|
||||||
return [$_[0][0], $_[1]]; // unfiltered, use the first command
|
if (!filter)
|
||||||
});
|
return [0, helpArray.map(function ($_) { return [$_[0][0], $_[1]]; })];
|
||||||
|
|
||||||
return buildLongestCommonSubstring(helpArray, filter);
|
return [0, buildLongestCommonSubstring(helpArray, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
command: function (filter)
|
commands: function (filter)
|
||||||
{
|
{
|
||||||
substrings = [];
|
substrings = [];
|
||||||
var completions = [];
|
var completions = [];
|
||||||
@@ -273,15 +283,16 @@ vimperator.Completion = function () //{{{
|
|||||||
{
|
{
|
||||||
for (var command in vimperator.commands)
|
for (var command in vimperator.commands)
|
||||||
completions.push([command.name, command.shortHelp]);
|
completions.push([command.name, command.shortHelp]);
|
||||||
return completions;
|
return [0, completions];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var command in vimperator.commands)
|
for (var command in vimperator.commands)
|
||||||
completions.push([command.longNames, command.shortHelp]);
|
completions.push([command.longNames, command.shortHelp]);
|
||||||
return buildLongestStartingSubstring(completions, filter);
|
|
||||||
|
return [0, buildLongestStartingSubstring(completions, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
option: function (filter, unfiltered)
|
options: function (filter, unfiltered)
|
||||||
{
|
{
|
||||||
substrings = [];
|
substrings = [];
|
||||||
var optionCompletions = [];
|
var optionCompletions = [];
|
||||||
@@ -290,6 +301,8 @@ vimperator.Completion = function () //{{{
|
|||||||
if (prefix)
|
if (prefix)
|
||||||
filter = filter.replace(prefix, "");
|
filter = filter.replace(prefix, "");
|
||||||
|
|
||||||
|
// needed for help-completions, don't return [start, options], just options
|
||||||
|
// FIXME: doesn't belong here to be honest (rather v.options.get(filter)) --mst
|
||||||
if (unfiltered)
|
if (unfiltered)
|
||||||
{
|
{
|
||||||
var options = [];
|
var options = [];
|
||||||
@@ -311,7 +324,7 @@ vimperator.Completion = function () //{{{
|
|||||||
continue;
|
continue;
|
||||||
options.push([prefix + option.name, option.shortHelp]);
|
options.push([prefix + option.name, option.shortHelp]);
|
||||||
}
|
}
|
||||||
return options;
|
return [0, options];
|
||||||
}
|
}
|
||||||
// check if filter ends with =, then complete current value
|
// check if filter ends with =, then complete current value
|
||||||
else if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
else if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
||||||
@@ -320,12 +333,9 @@ vimperator.Completion = function () //{{{
|
|||||||
for (var option in vimperator.options)
|
for (var option in vimperator.options)
|
||||||
{
|
{
|
||||||
if (option.hasName(filter))
|
if (option.hasName(filter))
|
||||||
{
|
return [filter.length + 1, [[option.value, ""]]];
|
||||||
optionCompletions.push([filter + "=" + option.value, ""]);
|
|
||||||
return optionCompletions;
|
|
||||||
}
|
}
|
||||||
}
|
return [0, optionCompletions];
|
||||||
return optionCompletions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't use b_l_s_s, since this has special requirements (the prefix)
|
// can't use b_l_s_s, since this has special requirements (the prefix)
|
||||||
@@ -357,10 +367,11 @@ vimperator.Completion = function () //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return optionCompletions;
|
return [0, optionCompletions];
|
||||||
},
|
},
|
||||||
|
|
||||||
buffer: function (filter)
|
// FIXME: items shouldn't be [[[a], b]], but [[a, b]] and only mapped if at all for bLCS --mst
|
||||||
|
buffers: function (filter)
|
||||||
{
|
{
|
||||||
substrings = [];
|
substrings = [];
|
||||||
var items = [];
|
var items = [];
|
||||||
@@ -390,10 +401,11 @@ vimperator.Completion = function () //{{{
|
|||||||
items.push([[(i + 1) + ": " + title, (i + 1) + ": " + url], url]);
|
items.push([[(i + 1) + ": " + title, (i + 1) + ": " + url], url]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!filter) return items.map(function ($_) {
|
|
||||||
return [$_[0][0], $_[1]];
|
if (!filter)
|
||||||
});
|
return [0, items.map(function ($_) { return [$_[0][0], $_[1]]; })];
|
||||||
return buildLongestCommonSubstring(items, filter);
|
|
||||||
|
return [0, buildLongestCommonSubstring(items, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
sidebar: function (filter)
|
sidebar: function (filter)
|
||||||
@@ -406,13 +418,13 @@ vimperator.Completion = function () //{{{
|
|||||||
nodes.push([menu.childNodes[i].label, ""]);
|
nodes.push([menu.childNodes[i].label, ""]);
|
||||||
|
|
||||||
if (!filter)
|
if (!filter)
|
||||||
return nodes;
|
return [0, nodes];
|
||||||
|
|
||||||
var mapped = nodes.map(function (node) {
|
var mapped = nodes.map(function (node) {
|
||||||
return [[node[0]], node[1]];
|
return [[node[0]], node[1]];
|
||||||
});
|
});
|
||||||
|
|
||||||
return buildLongestCommonSubstring(mapped, filter);
|
return [0, buildLongestCommonSubstring(mapped, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
javascript: function (str)
|
javascript: function (str)
|
||||||
@@ -422,6 +434,9 @@ vimperator.Completion = function () //{{{
|
|||||||
var objects = [];
|
var objects = [];
|
||||||
var filter = matches[3] || "";
|
var filter = matches[3] || "";
|
||||||
var start = matches[1].length - 1;
|
var start = matches[1].length - 1;
|
||||||
|
var offset = matches[1] ? matches[1].length : 0;
|
||||||
|
offset += matches[2] ? matches[2].length : 0;
|
||||||
|
|
||||||
if (matches[2])
|
if (matches[2])
|
||||||
{
|
{
|
||||||
var brackets = 0, parentheses = 0;
|
var brackets = 0, parentheses = 0;
|
||||||
@@ -488,7 +503,7 @@ vimperator.Completion = function () //{{{
|
|||||||
completions = [];
|
completions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildLongestStartingSubstring(completions, filter);
|
return [offset, buildLongestStartingSubstring(completions, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
// discard all entries in the 'urls' array, which don't match 'filter
|
// discard all entries in the 'urls' array, which don't match 'filter
|
||||||
@@ -523,8 +538,8 @@ vimperator.Completion = function () //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Longest Common Subsequence
|
// Longest Common Subsequence
|
||||||
// This shouldn't use buildLongestCommonSubstring
|
// This shouldn't use buildLongestCommonSubstring for performance
|
||||||
// for performance reasons, so as not to cycle through the urls twice
|
// reasons, so as not to cycle through the urls twice
|
||||||
outer:
|
outer:
|
||||||
for (var i = 0; i < urls.length; i++)
|
for (var i = 0; i < urls.length; i++)
|
||||||
{
|
{
|
||||||
@@ -609,51 +624,54 @@ vimperator.Completion = function () //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// FIXME: rename
|
// FIXME: rename
|
||||||
|
// TODO: get completions for "nested" command lines like ":time :js <tab>" or ":tab :he<tab>"
|
||||||
exTabCompletion: function (str)
|
exTabCompletion: function (str)
|
||||||
{
|
{
|
||||||
var [count, cmd, special, args] = vimperator.commands.parseCommand(str);
|
var [count, cmd, special, args] = vimperator.commands.parseCommand(str);
|
||||||
var completions = [];
|
var completions = [];
|
||||||
var start = 0;
|
var start = 0;
|
||||||
|
var exLength = 0;
|
||||||
|
|
||||||
// if there is no space between the command name and the cursor
|
// if there is no space between the command name and the cursor
|
||||||
// then get completions of the command name
|
// then get completions of the command name
|
||||||
var matches = str.match(/^(:*\d*)\w*$/);
|
var matches = str.match(/^(:*\d*)\w*$/);
|
||||||
if (matches)
|
if (matches)
|
||||||
{
|
return [matches[1].length, this.commands(cmd)[1]];
|
||||||
completions = this.command(cmd);
|
|
||||||
start = matches[1].length;
|
// dynamically get completions as specified with the command's completer function
|
||||||
}
|
|
||||||
else // dynamically get completions as specified with the command's completer function
|
|
||||||
{
|
|
||||||
var command = vimperator.commands.get(cmd);
|
var command = vimperator.commands.get(cmd);
|
||||||
if (command && command.completer)
|
if (command && command.completer)
|
||||||
{
|
{
|
||||||
matches = str.match(/^:*\d*\w+!?\s+/);
|
matches = str.match(/^:*\d*\w+!?\s+/);
|
||||||
start = matches ? matches[0].length : 0;
|
exLength = matches ? matches[0].length : 0;
|
||||||
|
|
||||||
// TODO: maybe we should move these checks to the complete functions
|
// // TODO: maybe we should move these checks to the complete functions
|
||||||
if (command.hasName("open") || command.hasName("tabopen") || command.hasName("winopen"))
|
// if (command.hasName("open") || command.hasName("tabopen") || command.hasName("winopen"))
|
||||||
{
|
// {
|
||||||
var skip = args.match(/^(.*,\s+)(.*)/); // start after the last ", "
|
// var skip = args.match(/^(.*,\s+)(.*)/); // start after the last ", "
|
||||||
if (skip)
|
// if (skip)
|
||||||
{
|
// {
|
||||||
start += skip[1].length;
|
// start += skip[1].length;
|
||||||
args = skip[2];
|
// args = skip[2];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (command.hasName("echo") || command.hasName("echoerr") || command.hasName("javascript"))
|
// else if (command.hasName("echo") || command.hasName("echoerr") || command.hasName("javascript"))
|
||||||
{
|
// {
|
||||||
var skip = args.match(/^(.*?)(\w*)$/); // start at beginning of the last word
|
// var skip = args.match(/^(.*?)(\w*)$/); // start at beginning of the last word
|
||||||
if (skip)
|
// if (skip)
|
||||||
start += skip[1].length;
|
// start += skip[1].length;
|
||||||
}
|
// }
|
||||||
|
// else if (command.hasName("source"))
|
||||||
|
// {
|
||||||
|
// var skip = args.match(/^(.*?)(\w*)$/); // start at beginning of the last word
|
||||||
|
// if (skip)
|
||||||
|
// start += skip[1].length;
|
||||||
|
// }
|
||||||
|
|
||||||
completions = command.completer.call(this, args);
|
[start, completions] = command.completer.call(this, args);
|
||||||
}
|
}
|
||||||
|
return [exLength + start, completions];
|
||||||
}
|
}
|
||||||
return [start, completions];
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
//}}}
|
//}}}
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ vimperator.IO = function ()//{{{
|
|||||||
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||||
.getService(Components.interfaces.nsIEnvironment);
|
.getService(Components.interfaces.nsIEnvironment);
|
||||||
|
|
||||||
|
const WINDOWS = navigator.platform == "Win32";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
@@ -53,8 +55,6 @@ vimperator.IO = function ()//{{{
|
|||||||
|
|
||||||
expandPath: function (path)
|
expandPath: function (path)
|
||||||
{
|
{
|
||||||
const WINDOWS = navigator.platform == "Win32";
|
|
||||||
|
|
||||||
// TODO: proper pathname separator translation like Vim
|
// TODO: proper pathname separator translation like Vim
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
path = path.replace("/", "\\", "g");
|
path = path.replace("/", "\\", "g");
|
||||||
@@ -96,7 +96,7 @@ vimperator.IO = function ()//{{{
|
|||||||
{
|
{
|
||||||
var pluginDir;
|
var pluginDir;
|
||||||
|
|
||||||
if (navigator.platform == "Win32")
|
if (WINDOWS)
|
||||||
pluginDir = "~/vimperator/plugin";
|
pluginDir = "~/vimperator/plugin";
|
||||||
else
|
else
|
||||||
pluginDir = "~/.vimperator/plugin";
|
pluginDir = "~/.vimperator/plugin";
|
||||||
@@ -108,10 +108,10 @@ vimperator.IO = function ()//{{{
|
|||||||
|
|
||||||
getRCFile: function ()
|
getRCFile: function ()
|
||||||
{
|
{
|
||||||
var rcFile1 = this.getFile(this.expandPath("~/.vimperatorrc"));
|
var rcFile1 = this.getFile("~/.vimperatorrc");
|
||||||
var rcFile2 = this.getFile(this.expandPath("~/_vimperatorrc"));
|
var rcFile2 = this.getFile("~/_vimperatorrc");
|
||||||
|
|
||||||
if (navigator.platform == "Win32")
|
if (WINDOWS)
|
||||||
[rcFile1, rcFile2] = [rcFile2, rcFile1]
|
[rcFile1, rcFile2] = [rcFile2, rcFile1]
|
||||||
|
|
||||||
if (rcFile1.exists() && rcFile1.isFile())
|
if (rcFile1.exists() && rcFile1.isFile())
|
||||||
@@ -124,12 +124,18 @@ vimperator.IO = function ()//{{{
|
|||||||
|
|
||||||
// return a nsILocalFile for path where you can call isDirectory(), etc. on
|
// return a nsILocalFile for path where you can call isDirectory(), etc. on
|
||||||
// caller must check with .exists() if the returned file really exists
|
// caller must check with .exists() if the returned file really exists
|
||||||
|
// also expands relative paths
|
||||||
getFile: function (path)
|
getFile: function (path)
|
||||||
{
|
{
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
createInstance(Components.interfaces.nsILocalFile);
|
||||||
|
|
||||||
file.initWithPath(this.expandPath(path));
|
// convert relative to absolute pathnames
|
||||||
|
path = this.expandPath(path);
|
||||||
|
if (!/^([a-zA-Z]+:|\/)/.test(path)) // starts not with either /, C: or file:
|
||||||
|
path = this.expandPath("~") + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir?
|
||||||
|
|
||||||
|
file.initWithPath(path);
|
||||||
return file;
|
return file;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -139,7 +145,7 @@ vimperator.IO = function ()//{{{
|
|||||||
{
|
{
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
createInstance(Components.interfaces.nsILocalFile);
|
||||||
if (navigator.platform == "Win32")
|
if (WINDOWS)
|
||||||
{
|
{
|
||||||
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "C:\\";
|
var dir = environmentService.get("TMP") || environmentService.get("TEMP") || "C:\\";
|
||||||
file.initWithPath(dir + "\\vimperator.tmp");
|
file.initWithPath(dir + "\\vimperator.tmp");
|
||||||
|
|||||||
Reference in New Issue
Block a user