From cfa515f62edaadda902787454c72c6d00d83e325 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 2 Jul 2007 06:57:11 +0000 Subject: [PATCH] add new Ctrl-^ mapping for selecting the alternate tab --- ChangeLog | 1 + chrome/content/vimperator/mappings.js | 26 +++++++++++++++++++++++++ chrome/content/vimperator/vimperator.js | 18 +++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4d9e9375..25e582a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@
 2007-07-02:
 	* version ???
+	* Ctrl-^ mapping for selecting the alternate tab/buffer
 	* QuickMarks support (new commands :qmarks/:qmarkadd/:qmarkdel and
 	  mappings go{a-z}, gn{a-z} and M{a-z}
 	* Multiline echo support
diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js
index 54634110..51c8f29c 100644
--- a/chrome/content/vimperator/mappings.js
+++ b/chrome/content/vimperator/mappings.js
@@ -298,6 +298,32 @@ function Mappings() //{{{
             flags: Mappings.flags.COUNT
         }
     ));
+    addDefaultMap(new Map(vimperator.modes.NORMAL, ['', ''],
+            function (args) {
+                if (vimperator.tabs.getTab() == vimperator.tabs.alternate)
+                {   
+                    vimperator.echoerr("E23: No alternate page");
+                    return;
+                }
+                
+                // NOTE: this currently relies on v.tabs.index() returning the
+                // currently selected tab index when passed null
+                var index = vimperator.tabs.index(vimperator.tabs.alternate);
+                
+                // TODO: since a tab close is more like a bdelete for us we
+                // should probably reopen the closed tab when a 'deleted'
+                // alternate is selected
+                if (index == -1)
+                    vimperator.echoerr("E86: Buffer does not exist")  // TODO: This should read "Buffer N does not exist"
+                else
+                    vimperator.tabs.select(index);
+            },
+            {   
+                short_help: "Select the alternate tab",
+                usage: [''],
+                help: "The alternate tab is the last selected tab. This provides a quick method of toggling between two tabs."
+            }
+    ));
     addDefaultMap(new Map(vimperator.modes.NORMAL, ["m"],
         function(mark) { vimperator.marks.add(mark) },
         {
diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js
index 7d67daab..414d34cf 100644
--- a/chrome/content/vimperator/vimperator.js
+++ b/chrome/content/vimperator/vimperator.js
@@ -368,6 +368,7 @@ function Events() //{{{
         vimperator.statusline.updateTabCount();
         updateBufferList();
         vimperator.setMode(); // trick to reshow the mode in the command line
+        vimperator.tabs.updateSelectionHistory();
     }, false);
     tabcontainer.addEventListener("TabClose",  function(event) {
         vimperator.statusline.updateTabCount()
@@ -378,6 +379,7 @@ function Events() //{{{
         vimperator.statusline.updateTabCount();
         updateBufferList();
         vimperator.setMode(); // trick to reshow the mode in the command line
+        vimperator.tabs.updateSelectionHistory();
     }, false);
 
     // this adds an event which is is called on each page load, even if the
@@ -910,6 +912,8 @@ function Tabs() //{{{
         return position;
     }
 
+    var alternates = [null, null];
+
     /////////////////////////////////////////////////////////////////////////////}}}
     ////////////////////// PUBLIC SECTION //////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////{{{
@@ -929,6 +933,7 @@ function Tabs() //{{{
 
         return getBrowser().tabContainer.selectedIndex;
     }
+
     this.count = function()
     {
         return getBrowser().mTabs.length;
@@ -1003,6 +1008,19 @@ function Tabs() //{{{
         }
         getBrowser().mTabContainer.selectedIndex = index;
     }
+
+    // TODO: when restarting a session FF selects the first tab and then the
+    // tab that was selected when the session was created.  As a result the
+    // alternate after a restart is often incorrectly tab 1 when there
+    // shouldn't be one yet.
+    this.updateSelectionHistory = function()
+    {
+        alternates = [this.getTab(), alternates[0]];
+        this.alternate = alternates[1];
+    }
+
+    this.alternate = this.getTab();
+
     //}}}
 } //}}}