From ea6069dc0679ec6977f6583fe59f8fe1d8e7b718 Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Mon, 14 May 2007 13:24:57 +0000 Subject: [PATCH] initial :tabmove command --- ChangeLog | 5 +++- chrome/content/vimperator/commands.js | 39 +++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b1e0856..75ac494f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@
 2007-05-02:
 	* version ???
+	* :tabmove command (by Doug Kearns)
+	* 'showstatuslinks' option to control where/if we show the destination of
+	a hovered link
 	* :version! shows firefox version page
 	* hovered links appear in the command line again, not statusbar
 	* :help now opens in the current tab even for xhtml pages like "about:"
@@ -10,7 +13,7 @@
 	* added :tabonly and :tabrewind and :tablast commands and some futher aliases :tabNext, etc. (by Doug Kearns)
 	* added vimparator.vim for .vimperatorrc syntax highlighting in the XPI (by Doug Kearns)
 	* Added keyword support for bookmarks to the :[tab]open commands
-	* many small bug fixes
+	* many small bug fixes and enhancements
 
 2007-05-02:
 	* version 0.4.1
diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index 4ef79787..be10296a 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -400,13 +400,15 @@ var g_commands = [/*{{{*/
         ["tabo[nly]"],
         "Close all other tabs",
         null,
-        function () {
-            tabs = getBrowser().mTabContainer.childNodes;
-            for (var i = tabs.length - 1; i >= 0; i--) {
-                if (tabs[i] != getBrowser().mCurrentTab)
-                    getBrowser().removeTab(tabs[i]);
-            }
-        },
+        function() { getBrowser().removeAllTabsBut(getBrowser().mCurrentTab); },
+        null
+    ],
+    [
+        ["tabmove", "tabm"],
+        ["tabm[ove] [N]"],
+        "Move the current tab after tab N",
+        "When N is 0 the current tab is made the first one.  Without N the current tab is made the last one.",
+        tab_move,
         null
     ],
     [
@@ -430,7 +432,7 @@ var g_commands = [/*{{{*/
         ["tabl[ast]"],
         "Switch to the last tab",
         null,
-        function(args, count) { tab_go(getBrowser().mTabContainer.childNodes.length); },
+        function(args, count) { tab_go(getBrowser().mTabs.length); },
         null
     ],
     [
@@ -1170,7 +1172,7 @@ function tokenize_ex(string, tag)
     }
 
     // 0 - count, 1 - cmd, 2 - special, 3 - args, 4 - heredoc tag
-    var matches = string.match(/^:*(\d+)?([a-zA-Z]+)(!)?(?:\s+(.*?))?$/);
+    var matches = string.match(/^:*(\d+)?([a-zA-Z]+)(!)?(?:\s+(.*?)\s*)?$/);
     if (!matches)
         return [null, null, null, null, null];
     matches.shift();
@@ -1655,7 +1657,7 @@ function tab_go(index)
         getBrowser().mTabContainer.advanceSelectedTab(1, true);
     else
     {
-        if (getBrowser().mTabContainer.childNodes.length < index)
+        if (getBrowser().mTabs.length < index)
             beep();
         else
             getBrowser().mTabContainer.selectedIndex = index-1;
@@ -1671,7 +1673,7 @@ function tab_remove(count, focus_left_tab, quit_on_last_tab)
 {
     if (count < 1) count = 1;
 
-    if (quit_on_last_tab >= 1 && getBrowser().mTabContainer.childNodes.length <= count)
+    if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count)
         quit(quit_on_last_tab == 2);
 
     var tab = getBrowser().mCurrentTab;
@@ -1680,6 +1682,21 @@ function tab_remove(count, focus_left_tab, quit_on_last_tab)
     getBrowser().removeTab(tab);
 }
 
+function tab_move(position)
+{
+    if (!position.match(/^(\d+|)$/))
+    {
+        vimperator.echoerr("E488: Trailing characters");
+        return;
+    }
+
+    var last = getBrowser().mTabs.length - 1;
+    if (position == "" || position > last)
+        position = last;
+
+    getBrowser().moveTabTo(getBrowser().mCurrentTab, parseInt(position));
+}
+
 function bufshow(filter, in_comp_window)
 {
     if (in_comp_window) // fill the completion list