From 16a9c56fbe7f0fdac694e7fbe058035734b8da1a Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 12 Aug 2008 11:23:01 +0000 Subject: [PATCH] add prefix count support to :tabprevious, :bprevious, :tabnext, :bnext etc --- NEWS | 1 + content/tabs.js | 59 +++++++++++++++++++++++++++++++------------ locale/en-US/tabs.txt | 16 ++++++------ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/NEWS b/NEWS index c9085178..10398beb 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ generous donation which made this behavior possible) * IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just too unpredictable + * :tabprevious, :bprevious, :tabnext, :bnext and friends now accept a prefix count * add :comclear and :delcommand * add a special version to :hardcopy to skip the Print dialog * add :bl[ast], :bf[irst], :br[ewind] to go to first/last tab diff --git a/content/tabs.js b/content/tabs.js index 92cda9ff..2cc71c91 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -304,31 +304,56 @@ liberator.Tabs = function () //{{{ "Switch to the last tab", function () { liberator.tabs.select("$", false); }); - // TODO: count support + // TODO: "Zero count" if 0 specified as arg liberator.commands.add(["tabp[revious]", "tp[revious]", "tabN[ext]", "tN[ext]", "bp[revious]", "bN[ext]"], "Switch to the previous tab or go [count] tabs back", - function (args) + function (args, special, count) { - if (!args) - liberator.tabs.select("-1", true); - else if (/^\d+$/.test(args)) - liberator.tabs.select("-" + args, true); // FIXME: urgh! + // count is ignored if an arg is specified, as per Vim + if (args) + { + if (/^\d+$/.test(args)) + liberator.tabs.select("-" + args, true); // FIXME: urgh! + else + liberator.echoerr("E488: Trailing characters"); + } + else if (count > 0) + { + liberator.tabs.select("-" + count, true); + } else - liberator.echoerr("E488: Trailing characters"); + { + liberator.tabs.select("-1", true); + } }); - // TODO: count support + // TODO: "Zero count" if 0 specified as arg liberator.commands.add(["tabn[ext]", "tn[ext]", "bn[ext]"], "Switch to the next or [count]th tab", - function (args) + function (args, special, count) { - if (!args) + if (args || count > 0) { - liberator.tabs.select("+1", true); - } - else if (/^\d+$/.test(args)) - { - var index = parseInt(args, 10) - 1; + var index; + + // count is ignored if an arg is specified, as per Vim + if (args) + { + if (/^\d+$/.test(args)) + { + index = args - 1; + } + else + { + liberator.echoerr("E488: Trailing characters"); + return; + } + } + else + { + index = count - 1; + } + if (index < liberator.tabs.count) liberator.tabs.select(index, true); else @@ -336,7 +361,7 @@ liberator.Tabs = function () //{{{ } else { - liberator.echoerr("E488: Trailing characters"); + liberator.tabs.select("+1", true); } }); @@ -347,6 +372,7 @@ liberator.Tabs = function () //{{{ if (liberator.config.name == "Vimperator") { + // TODO: add count support liberator.commands.add(["b[uffer]"], "Switch to a buffer", function (args, special) { liberator.tabs.switchTo(args, special); }, @@ -373,6 +399,7 @@ liberator.Tabs = function () //{{{ "Reload all tab pages", function (args, special) { liberator.tabs.reloadAll(special); }); + // TODO: add count support liberator.commands.add(["tabm[ove]"], "Move the current tab after tab N", function (args, special) diff --git a/locale/en-US/tabs.txt b/locale/en-US/tabs.txt index a62bb041..56347df3 100644 --- a/locale/en-US/tabs.txt +++ b/locale/en-US/tabs.txt @@ -120,9 +120,9 @@ ________________________________________________________________________________ |:bn| |:bnext| |:tn| |:tnext| |:tabn| |:tabnext| -||:tabn[ext] [count]|| + -||:tn[ext] [count]|| + -||:bn[ext] [count]|| +||:[count]tabn[ext] [count]|| + +||:[count]tn[ext] [count]|| + +||:[count]bn[ext] [count]|| ________________________________________________________________________________ Switch to the next or [count]th tab. Cycles to the first tab when the last is selected and {count} is not specified. @@ -137,11 +137,11 @@ ________________________________________________________________________________ |:bN| |:bNext| |:bp| |:bprevious| |:tN| |:tNext| |:tabN| |:tabNext| |:tp| |:tprevious| |:tabp| |:tabprevious| -||:tabp[revious] [count]|| + -||:tp[revious] [count]|| + -||:tabN[ext] [count]|| + -||:bp[revious] [count]|| + -||:bN[ext] [count]|| +||:[count]tabp[revious] [count]|| + +||:[count]tp[revious] [count]|| + +||:[count]tabN[ext] [count]|| + +||:[count]bp[revious] [count]|| + +||:[count]bN[ext] [count]|| ________________________________________________________________________________ Switch to the previous tab or go [count] tabs back. Wraps around from the first tab to the last tab.