-
Notifications
You must be signed in to change notification settings - Fork 280
Code snippets for custom keyboard shortcuts
Firefox already has a very large number of keyboard shortcuts, and other addons also provide their own keyboard shortcuts, I cannot find out safe combinations for my features. So I gave up and decided to provide only APIs for other addons. Please use other addons (for example: Dorando keyconfig) to customize keyboard shortcuts which can define custom actions based on scripts. Sorry.
See also:
- Wiki page collecting keyboard shortcuts · Issue #669
- Toggle hotkey · Issue #156
- Feature Request: Close Group Shortcut · Issue #274
- Keyboard Shortcuts for modifying tree · Issue #772
- Supporting PageUp, PageDown, Home, End keys in the tab list · Issue #836
- caicui's Vimperator plugin to operate tabs with TST
Ctrl-PageUp
and Ctrl-PageDown
are available to switch to previous/next tab by default.
Firefox also has additional keyboard shortcuts to move focus between tabs, and to move tabs, but they are deactivated by default. They can be re-activated, but better results might be obtained using the scripts below. In that case, the following CSS is not required.
If you want to use Firefox's additional keyboard shortcuts anyway, you can activate them in userChrome.css like:
.tabbrowser-tab {
-moz-user-focus: normal !important;
}
That way, clicking on a tab gives focus to the tab bar. Then shortcuts like up/down arrow and home/end will apply to the tab bar instead of the page's contents. Ctrl-Up/Left and Ctrl-Down/Right can be used to move tabs, but the "Move tabs" scripts below give better control.
Note that on macOS / OS X, this does not currently (Firefox 47) work as expected.
Using Dorando keyconfig for example, open its preferences, click "Add a new key", give it a name, and paste one of the scripts in the /* CODE */
section. Then select the key combination for the shortcut. You may also use FireGestures or other customization addons.
if (gBrowser.treeStyleTab.tabbarShown) {
gBrowser.treeStyleTab.hideTabbar();
} else {
gBrowser.treeStyleTab.showTabbar();
}
gBrowser.treeStyleTab.removeTabSubtree(gBrowser.selectedTab);
TreeStyleTabService.getAncestorTabs(gBrowser.selectedTab).forEach(function(aTab) {
gBrowser.reloadTab(aTab);
});
var root = TreeStyleTabService.getRootTab(gBrowser.selectedTab);
var prev = TreeStyleTabService.getPreviousSiblingTab(root);
if (prev)
gBrowser.selectedTab = prev;
var root = TreeStyleTabService.getRootTab(gBrowser.selectedTab);
var next = TreeStyleTabService.getNextSiblingTab(root);
if (next)
gBrowser.selectedTab = next;
TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab);
openUILinkIn(BROWSER_NEW_TAB_URL, "tab");
var parent = TreeStyleTabService.getParentTab(gBrowser.selectedTab);
if (parent)
TreeStyleTabService.readyToOpenChildTab(parent);
openUILinkIn(BROWSER_NEW_TAB_URL, "tab");
openUILinkIn(BROWSER_NEW_TAB_URL, "tab");
gBrowser.treeStyleTab.demoteCurrentTab();
gBrowser.treeStyleTab.promoteCurrentTab();
var tab = gBrowser.selectedTab, b = gBrowser.treeStyleTab.getTabBrowserFromChild(tab).treeStyleTab, next = b.getNextVisibleTab(tab);
if (next) {
var getTabLevel = (tab) => b.getAncestorTabs(tab).length;
var nextLevel = getTabLevel(next), tabLevel = getTabLevel(tab);
if (nextLevel >= tabLevel) {
if (nextLevel > tabLevel)
next = b.getNextSiblingTab(tab);
if (next) {
while (b.hasChildTabs(next))
next = b.getLastChildTab(next);
gBrowser.moveTabTo(tab, next._tPos);
}
}
}
var tab = gBrowser.selectedTab, b = gBrowser.treeStyleTab.getTabBrowserFromChild(tab).treeStyleTab, prev = b.getPreviousVisibleTab(tab);
if (prev) {
var getTabLevel = (tab) => b.getAncestorTabs(tab).length;
var prevLevel = getTabLevel(prev), tabLevel = getTabLevel(tab);
if (prevLevel >= tabLevel) {
if (prevLevel > tabLevel)
prev = b.getPreviousSiblingTab(tab);
gBrowser.moveTabTo(tab, prev._tPos);
var newLevel = getTabLevel(tab);
while (newLevel-- > tabLevel)
b.promoteTab(tab);
}
}
First install "Multiple Tab Handler" to get "Duplicate" function in tab context (right click) menu.
TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab);
gBrowser.duplicateTab(gBrowser.mCurrentTab);
gBrowser.selectedTab = gBrowser.duplicateTab(gBrowser.mCurrentTab);
gBrowser.treeStyleTab.promoteCurrentTab();
gBrowser.selectedTab = gBrowser.duplicateTab(gBrowser.mCurrentTab);
setTimeout("gBrowser.moveTabTo(gBrowser.selectedTab);", 0);