1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 10:08:00 +01:00

sort :commands for tab-completion

This commit is contained in:
Martin Stubenschrott
2008-03-01 00:27:10 +00:00
parent 3c203e5563
commit 48a79ca3cf
4 changed files with 13 additions and 15 deletions

View File

@@ -72,7 +72,7 @@ vimperator.Command = function (specs, description, action, extraInfo) //{{{
// return the primary command name (the long name of the first spec listed) // return the primary command name (the long name of the first spec listed)
this.name = this.longNames[0]; this.name = this.longNames[0];
this.names = expandedSpecs.names; // return all command name aliases this.names = expandedSpecs.names; // return all command name aliases
this.description = extraInfo.description || ""; this.description = description || "";
this.action = action; this.action = action;
this.completer = extraInfo.completer || null; this.completer = extraInfo.completer || null;
this.args = extraInfo.args || []; this.args = extraInfo.args || [];
@@ -414,14 +414,6 @@ vimperator.Commands = function () //{{{
return def; return def;
} }
function commandsIterator()
{
for (var i = 0; i < exCommands.length; i++)
yield exCommands[i];
throw StopIteration;
}
function getUserCommands(name) function getUserCommands(name)
{ {
var matches = []; var matches = [];
@@ -467,7 +459,11 @@ vimperator.Commands = function () //{{{
__iterator__: function () __iterator__: function ()
{ {
return commandsIterator(); var sorted = exCommands.sort(function (cmd1, cmd2) { return cmd1.name > cmd2.name; });
for (var i = 0; i < sorted.length; i++)
yield sorted[i];
throw StopIteration;
}, },
add: function (names, description, action, extra) add: function (names, description, action, extra)

View File

@@ -302,6 +302,7 @@ vimperator.Completion = function () //{{{
{ {
substrings = []; substrings = [];
var completions = []; var completions = [];
if (!filter) if (!filter)
{ {
for (var command in vimperator.commands) for (var command in vimperator.commands)

View File

@@ -42,7 +42,7 @@ vimperator.Map = function (modes, cmds, description, action, extraInfo) //{{{
this.action = action; this.action = action;
this.flags = extraInfo.flags || 0; this.flags = extraInfo.flags || 0;
this.description = extraInfo.description || ""; this.description = description || "";
this.rhs = extraInfo.rhs || null; this.rhs = extraInfo.rhs || null;
this.noremap = extraInfo.noremap || false; this.noremap = extraInfo.noremap || false;
}; };

View File

@@ -669,7 +669,6 @@ vimperator.CommandLine = function () //{{{
completionlist.selectItem(completionIndex); completionlist.selectItem(completionIndex);
} }
if (completionIndex == -1 && !longest) // wrapped around matches, reset command line if (completionIndex == -1 && !longest) // wrapped around matches, reset command line
{ {
if (full && completions.length > 1) if (full && completions.length > 1)
@@ -679,12 +678,14 @@ vimperator.CommandLine = function () //{{{
} }
else else
{ {
var compl = null;
if (longest && completions.length > 1) if (longest && completions.length > 1)
var compl = vimperator.completion.getLongestSubstring(); compl = vimperator.completion.getLongestSubstring();
else if (full) else if (full)
var compl = completions[completionIndex][0]; compl = completions[completionIndex][0];
else if (completions.length == 1) else if (completions.length == 1)
var compl = completions[0][0]; compl = completions[0][0];
if (compl) if (compl)
{ {
setCommand(command.substring(0, completionStartIndex) + compl + completionPostfix); setCommand(command.substring(0, completionStartIndex) + compl + completionPostfix);