mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:17:58 +01:00
initial Command/Commands implementation - replacing g_commands
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -74,31 +74,29 @@ function build_longest_starting_substring(list, filter)/*{{{*/
|
||||
//var filter_length = filter.length;
|
||||
for (var i = 0; i < list.length; i++)
|
||||
{
|
||||
var command_names = command_long_names(list[i]);
|
||||
for (var j = 0; j < command_names.length; j++)
|
||||
for (var j = 0; j < list[i][COMMANDS].length; j++)
|
||||
{
|
||||
if (command_names[j].indexOf(filter) != 0)
|
||||
if (list[i][0][j].indexOf(filter) != 0)
|
||||
continue;
|
||||
if (g_substrings.length == 0)
|
||||
{
|
||||
var length = command_names[j].length;
|
||||
var length = list[i][COMMANDS][j].length;
|
||||
for (var k = filter.length; k <= length; k++)
|
||||
g_substrings.push(command_names[j].substring(0, k));
|
||||
g_substrings.push(list[i][COMMANDS][j].substring(0, k));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_substrings = g_substrings.filter(function($_) {
|
||||
return command_names[j].indexOf($_) == 0;
|
||||
return list[i][COMMANDS][j].indexOf($_) == 0;
|
||||
});
|
||||
}
|
||||
filtered.push([command_names[j], list[i][SHORTHELP]]);
|
||||
filtered.push([list[i][COMMANDS][j], list[i][SHORTHELP]]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}/*}}}*/
|
||||
|
||||
|
||||
/*
|
||||
* filter a list of urls
|
||||
*
|
||||
@@ -257,12 +255,13 @@ function get_help_completions(filter)/*{{{*/
|
||||
{
|
||||
var help_array = [];
|
||||
g_substrings = [];
|
||||
help_array = help_array.concat(g_commands.map(function($_) {
|
||||
return [
|
||||
$_[COMMANDS].map(function($_) { return ":" + $_; }),
|
||||
$_[SHORTHELP]
|
||||
];
|
||||
}));
|
||||
for (var command in vimperator.commands)
|
||||
{
|
||||
help_array.push([command.long_names.map(function($_) {
|
||||
return ":" + $_;
|
||||
}),
|
||||
command.short_help])
|
||||
}
|
||||
settings = get_settings_completions(filter, true);
|
||||
help_array = help_array.concat(settings.map(function($_) {
|
||||
return [
|
||||
@@ -284,10 +283,17 @@ function get_command_completions(filter)/*{{{*/
|
||||
{
|
||||
//g_completions = [];
|
||||
g_substrings = [];
|
||||
if (!filter) return g_commands.map(function($_) {
|
||||
return [command_name($_), $_[SHORTHELP]];
|
||||
});
|
||||
return build_longest_starting_substring(g_commands, filter);
|
||||
var completions = []
|
||||
if (!filter)
|
||||
{
|
||||
for (var command in vimperator.commands)
|
||||
completions.push([command.name, command.short_help]);
|
||||
return completions;
|
||||
}
|
||||
|
||||
for (var command in vimperator.commands)
|
||||
completions.push([command.long_names, null, command.short_help]); // # FIXME: just return it in the format expected by blss() for now -- djk
|
||||
return build_longest_starting_substring(completions, filter);
|
||||
}/*}}}*/
|
||||
|
||||
function get_settings_completions(filter, unfiltered)/*{{{*/
|
||||
@@ -415,12 +421,12 @@ function exTabCompletion(str)
|
||||
completions = get_command_completions(cmd);
|
||||
start = matches[1].length;
|
||||
}
|
||||
else // dynamically get completions as specified in the g_commands array
|
||||
else // dynamically get completions as specified with the command's completer function
|
||||
{
|
||||
var command = get_command(cmd);
|
||||
if (command && command[COMPLETEFUNC])
|
||||
var command = vimperator.commands.get(cmd);
|
||||
if (command && command.completer)
|
||||
{
|
||||
completions = command[COMPLETEFUNC].call(this, args);
|
||||
completions = command.completer.call(this, args);
|
||||
// if (command[COMMANDS][0] == "open" ||
|
||||
// command[COMMANDS][0] == "tabopen" ||
|
||||
// command[COMMANDS][0] == "winopen")
|
||||
|
||||
@@ -458,15 +458,14 @@ function Search()
|
||||
}
|
||||
|
||||
// @todo nicer way to register commands?
|
||||
g_commands.push(
|
||||
[
|
||||
["noh[lsearch]"],
|
||||
["noh[lsearch]"],
|
||||
"Clear the current selection",
|
||||
"",
|
||||
vimperator.commands.add(new Command(["noh[lsearch]"],
|
||||
clearSelection,
|
||||
null
|
||||
]
|
||||
);
|
||||
{
|
||||
usage: ["noh[lsearch]"],
|
||||
short_help: "Clear the current selection",
|
||||
help: null,
|
||||
completer: null
|
||||
}
|
||||
));
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -92,7 +92,7 @@ function help(section, easter)
|
||||
ret += "Sorry, no help available";
|
||||
// the tags which are printed on the top right
|
||||
ret += '</td><td class="tag" valign="top">';
|
||||
var names = command_names(commands[i]);
|
||||
var names = commands[i][COMMANDS];
|
||||
for (var j=0; j < names.length; j++)
|
||||
{
|
||||
var cmd_name = names[j];
|
||||
@@ -176,7 +176,10 @@ function help(section, easter)
|
||||
mappings += '<span id="holy-grail">You found it, Arthur!</span>\n';
|
||||
|
||||
var commands = '<h2>Commands</h2><p><table class="vimperator commands">\n';
|
||||
commands += makeHelpString(g_commands, "#632610", ":", "", null);
|
||||
var all_commands = [];
|
||||
for (var command in vimperator.commands)
|
||||
all_commands.push([command.names, command.usage, command.short_help, command.help]);
|
||||
commands += makeHelpString(all_commands, "#632610", ":", "", null);
|
||||
commands += '</table></p>';
|
||||
if (section && section == '42')
|
||||
commands += '<p id="42">What is the meaning of life, the universe and everything?<br/>' +
|
||||
|
||||
@@ -91,7 +91,7 @@ function Mappings()//{{{
|
||||
}
|
||||
}
|
||||
|
||||
var mappingsIterator = function(mode)
|
||||
function mappingsIterator(mode)
|
||||
{
|
||||
var mappings;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user