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

generate errors for Ex tab commands in the command rather than in v.tabs

This commit is contained in:
Doug Kearns
2007-12-02 09:07:21 +00:00
parent 85520073b4
commit 290ba70b6f
2 changed files with 25 additions and 23 deletions

View File

@@ -2050,11 +2050,24 @@ vimperator.Commands = function () //{{{
} }
)); ));
commandManager.add(new vimperator.Command(["tabm[ove]"], commandManager.add(new vimperator.Command(["tabm[ove]"],
function (args, special) { vimperator.tabs.move(getBrowser().mCurrentTab, args, special); }, function (args, special)
{
// FIXME: tabmove! N should probably produce an error
if (!/^([+-]?\d+|)$/.test(args))
{
vimperator.echoerr("E488: Trailing characters");
return;
}
if (!args)
args = "$"; // if not specified, move to the last tab
vimperator.tabs.move(getBrowser().mCurrentTab, args, special);
},
{ {
usage: ["tabm[ove] [N]", "tabm[ove][!] +N | -N"], usage: ["tabm[ove] [N]", "tabm[ove][!] +N | -N"],
shortHelp: "Move the current tab after tab N", shortHelp: "Move the current tab after tab N",
help: "When N is 0 the current tab is made the first one. Without N the current tab is made the last one. " + help: "When N is 0 the current tab is made the first one. Without N the current tab is made the last one. " +
"N can also be prefixed with '+' or '-' to indicate a relative movement. If <code class=\"command\">!</code> is specified the movement wraps around the start or end of the tab list." "N can also be prefixed with '+' or '-' to indicate a relative movement. If <code class=\"command\">!</code> is specified the movement wraps around the start or end of the tab list."
} }
)); ));

View File

@@ -56,25 +56,18 @@ vimperator.Tabs = function () //{{{
if (typeof spec === "number") if (typeof spec === "number")
position = spec; position = spec;
else if (spec === "$") else if (spec === "$")
return last; position = last;
else if (!/^([+-]?\d+|)$/.test(spec)) else if (/^[+-]\d+$/.test(spec))
{ position += parseInt(spec, 10);
// TODO: move error reporting to ex-command? else if (/^\d+$/.test(spec))
vimperator.echoerr("E488: Trailing characters"); position = parseInt(spec, 10);
return false;
}
else else
{ return -1;
if (/^([+-]\d+)$/.test(spec)) // relative position +/-N
position += parseInt(spec, 10);
else // absolute position
position = parseInt(spec, 10);
}
if (position > last) if (position > last)
position = wrap ? position % length : last; position = wrap ? position % length : last;
else if (position < 0) else if (position < 0)
position = wrap ? (position % length) + length: 0; position = wrap ? (position % length) + length : 0;
return position; return position;
} }
@@ -132,15 +125,10 @@ vimperator.Tabs = function () //{{{
return getBrowser().mTabContainer.selectedItem; return getBrowser().mTabContainer.selectedItem;
}, },
// spec == "" moves the tab to the last position as per Vim
// wrap causes the movement to wrap around the start and end of the tab list // wrap causes the movement to wrap around the start and end of the tab list
// NOTE: position is a 0 based index // NOTE: position is a 0 based index
// FIXME: tabmove! N should probably produce an error
move: function (tab, spec, wrap) move: function (tab, spec, wrap)
{ {
if (spec === "")
spec = "$"; // if not specified, move to the last tab -> XXX: move to ex handling?
var index = indexFromSpec(spec, wrap); var index = indexFromSpec(spec, wrap);
getBrowser().moveTabTo(tab, index); getBrowser().moveTabTo(tab, index);
}, },
@@ -209,10 +197,11 @@ vimperator.Tabs = function () //{{{
select: function (spec, wrap) select: function (spec, wrap)
{ {
var index = indexFromSpec(spec, wrap); var index = indexFromSpec(spec, wrap);
if (index === false) // FIXME:
if (index === -1)
{ {
vimperator.beep(); // XXX: move to ex-handling? vimperator.beep(); // XXX: move to ex-handling?
return false; return;
} }
getBrowser().mTabContainer.selectedIndex = index; getBrowser().mTabContainer.selectedIndex = index;
}, },