1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 20:27:58 +01:00

initial Command/Commands implementation - replacing g_commands

This commit is contained in:
Doug Kearns
2007-06-06 06:42:49 +00:00
parent 4f6ab64000
commit e47ad6187e
5 changed files with 711 additions and 610 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -74,31 +74,29 @@ function build_longest_starting_substring(list, filter)/*{{{*/
//var filter_length = filter.length; //var filter_length = filter.length;
for (var i = 0; i < list.length; i++) for (var i = 0; i < list.length; i++)
{ {
var command_names = command_long_names(list[i]); for (var j = 0; j < list[i][COMMANDS].length; j++)
for (var j = 0; j < command_names.length; j++)
{ {
if (command_names[j].indexOf(filter) != 0) if (list[i][0][j].indexOf(filter) != 0)
continue; continue;
if (g_substrings.length == 0) 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++) 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 else
{ {
g_substrings = g_substrings.filter(function($_) { 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; break;
} }
} }
return filtered; return filtered;
}/*}}}*/ }/*}}}*/
/* /*
* filter a list of urls * filter a list of urls
* *
@@ -257,12 +255,13 @@ function get_help_completions(filter)/*{{{*/
{ {
var help_array = []; var help_array = [];
g_substrings = []; g_substrings = [];
help_array = help_array.concat(g_commands.map(function($_) { for (var command in vimperator.commands)
return [ {
$_[COMMANDS].map(function($_) { return ":" + $_; }), help_array.push([command.long_names.map(function($_) {
$_[SHORTHELP] return ":" + $_;
]; }),
})); command.short_help])
}
settings = get_settings_completions(filter, true); settings = get_settings_completions(filter, true);
help_array = help_array.concat(settings.map(function($_) { help_array = help_array.concat(settings.map(function($_) {
return [ return [
@@ -284,10 +283,17 @@ function get_command_completions(filter)/*{{{*/
{ {
//g_completions = []; //g_completions = [];
g_substrings = []; g_substrings = [];
if (!filter) return g_commands.map(function($_) { var completions = []
return [command_name($_), $_[SHORTHELP]]; if (!filter)
}); {
return build_longest_starting_substring(g_commands, 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)/*{{{*/ function get_settings_completions(filter, unfiltered)/*{{{*/
@@ -415,12 +421,12 @@ function exTabCompletion(str)
completions = get_command_completions(cmd); completions = get_command_completions(cmd);
start = matches[1].length; 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); var command = vimperator.commands.get(cmd);
if (command && command[COMPLETEFUNC]) if (command && command.completer)
{ {
completions = command[COMPLETEFUNC].call(this, args); completions = command.completer.call(this, args);
// if (command[COMMANDS][0] == "open" || // if (command[COMMANDS][0] == "open" ||
// command[COMMANDS][0] == "tabopen" || // command[COMMANDS][0] == "tabopen" ||
// command[COMMANDS][0] == "winopen") // command[COMMANDS][0] == "winopen")

View File

@@ -458,15 +458,14 @@ function Search()
} }
// @todo nicer way to register commands? // @todo nicer way to register commands?
g_commands.push( vimperator.commands.add(new Command(["noh[lsearch]"],
[
["noh[lsearch]"],
["noh[lsearch]"],
"Clear the current selection",
"",
clearSelection, clearSelection,
null {
] usage: ["noh[lsearch]"],
); short_help: "Clear the current selection",
help: null,
completer: null
}
));
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -92,7 +92,7 @@ function help(section, easter)
ret += "Sorry, no help available"; ret += "Sorry, no help available";
// the tags which are printed on the top right // the tags which are printed on the top right
ret += '</td><td class="tag" valign="top">'; 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++) for (var j=0; j < names.length; j++)
{ {
var cmd_name = names[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'; mappings += '<span id="holy-grail">You found it, Arthur!</span>\n';
var commands = '<h2>Commands</h2><p><table class="vimperator commands">\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>'; commands += '</table></p>';
if (section && section == '42') if (section && section == '42')
commands += '<p id="42">What is the meaning of life, the universe and everything?<br/>' + commands += '<p id="42">What is the meaning of life, the universe and everything?<br/>' +

View File

@@ -91,7 +91,7 @@ function Mappings()//{{{
} }
} }
var mappingsIterator = function(mode) function mappingsIterator(mode)
{ {
var mappings; var mappings;