Last Tab

I wrote a quick add-on tonight to fill a gap in how I use Firefox to browser the web.

The Gap

The usability gap happens when I have some reference like documentation or a calendar app open as a pinned tab (I'm addicted to pinning things I know I'll need later). At the same time I'll often be switching to a newly opened tab and then back to the original tab, back and forth, using the mouse or the trackpad. In Firefox you can hit Ctrl or Command + 9 to go back to the most recent tab, but hitting the same key binding again does nothing.

The Solution

What I wanted was a way to flip back and forth between both tabs - and this is exactly what 'Last Tab' does. If I've just been in a particular tab several tabs over for my current position, hitting CMD+Shift+\ not only gets me back to that tab - hitting CMD+Shift+\ again gets me back to my current tab safe and sound.

I'm still not 100% sure how useful it is - so far all the win seems to come from searching for a tab you want to change to first via the awesomebar, then flipping between that one and the current tab using last-tab. It's remarkable how little code is involved, thanks to the Add-on SDK:

const tabs = require('sdk/tabs');
const { Hotkey } = require("sdk/hotkeys");

let lastTab = null,
  thisTab = tabs.activeTab;

tabs.on('activate', function(tab) {
  lastTab = thisTab;
  thisTab = tab;
});

tabs.on('close', function(tab) {
  if (tab === thisTab) thisTab = null;
  if (tab === lastTab) lastTab = null;
});

let showHotKey = Hotkey({
  combo: "meta-shift-\\",
  onPress: function() {
    if (lastTab) {
      lastTab.activate();
    }
  }
});

The code is on Github, including a build you can install. If you're a particularly keyboard-driven Firefox user ( personally I feel like a loser when I use the trackpad ) maybe it will be useful to you.

Jeff Griffiths

Author

Jeff Griffiths

Open Web hacker and Product Manager at Mozilla.