diff --git a/content/commands.js b/content/commands.js index 056696b8..8d30576b 100644 --- a/content/commands.js +++ b/content/commands.js @@ -2050,11 +2050,24 @@ vimperator.Commands = function () //{{{ } )); 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"], 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 ! is specified the movement wraps around the start or end of the tab list." } )); diff --git a/content/tabs.js b/content/tabs.js index 199864d4..0643b421 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -56,25 +56,18 @@ vimperator.Tabs = function () //{{{ if (typeof spec === "number") position = spec; else if (spec === "$") - return last; - else if (!/^([+-]?\d+|)$/.test(spec)) - { - // TODO: move error reporting to ex-command? - vimperator.echoerr("E488: Trailing characters"); - return false; - } + position = last; + else if (/^[+-]\d+$/.test(spec)) + position += parseInt(spec, 10); + else if (/^\d+$/.test(spec)) + position = parseInt(spec, 10); else - { - if (/^([+-]\d+)$/.test(spec)) // relative position +/-N - position += parseInt(spec, 10); - else // absolute position - position = parseInt(spec, 10); - } + return -1; if (position > last) position = wrap ? position % length : last; else if (position < 0) - position = wrap ? (position % length) + length: 0; + position = wrap ? (position % length) + length : 0; return position; } @@ -132,15 +125,10 @@ vimperator.Tabs = function () //{{{ 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 // NOTE: position is a 0 based index - // FIXME: tabmove! N should probably produce an error 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); getBrowser().moveTabTo(tab, index); }, @@ -209,10 +197,11 @@ vimperator.Tabs = function () //{{{ select: function (spec, wrap) { var index = indexFromSpec(spec, wrap); - if (index === false) + // FIXME: + if (index === -1) { vimperator.beep(); // XXX: move to ex-handling? - return false; + return; } getBrowser().mTabContainer.selectedIndex = index; },