diff options
author | teramako | 2010-12-09 23:29:24 +0900 |
---|---|---|
committer | teramako | 2010-12-09 23:29:24 +0900 |
commit | d85f71c34cb2e782f9310d6a26a81c616b6ae422 (patch) | |
tree | a585aaf1b4f754db569b9e59f0bd49846e787a20 | |
parent | e6b444e49406576358a9a6c4666f5a69bf147032 (diff) | |
download | vimperator-plugins-d85f71c34cb2e782f9310d6a26a81c616b6ae422.tar.bz2 |
overwrite 'd' and 'D'
after removed tab
'd': select a right hand tab in visible tabs
'D': select a left hand tab in visible tabs
if all visible tabs are removed, switch group
-rw-r--r-- | panorama.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/panorama.js b/panorama.js index 4b686db..fe879ae 100644 --- a/panorama.js +++ b/panorama.js @@ -342,6 +342,65 @@ function switchToGroup (spec, wrap) { groupSwitch(index, wrap); } // }}} +/** + * removeTab {{{ + * @param {Element} tab + * @param {Number} count + * @param {Boolean} focusLeftTab + * @param {Number} quitOnLastTab + * @see tabs.remove + */ +function removeTab (tab, count, focusLeftTab, quitOnLastTab) { + const gb = gBrowser; + function remove(tab) { + if (gb.tabs.length > 1) { + gb.removeTab(tab); + } else if (buffer.URL != "about:blank" || gb.webNavigation.sessionHistory.count > 0) { + gb.loadURI("about:blank"); + } else { + liberator.beep(); + } + } + if (typeof count != "number" || count < 1) + count = 1; + + if (quitOnLastTab >= 1 && gb.tabs.length <= count) { + if (liberator.windows.length > 1) + window.close(); + else + liberator.quit(quitOnLastTab == 2); + + return; + } + let vTabs = gb.visibleTabs; + let index = vTabs.indexOf(tab); + liberator.assert(index >= 0, "No such tab(s) in the current tabs"); + + let start, end, selIndex; + if (focusLeftTab) { + end = index; + start = index - count + 1; + if (start < 0) { + start = 0; + } + selIndex = start - 1; + if (selIndex < 0) + selIndex = 0; + } else { + start = index; + end = index + count - 1; + if (end >= vTabs.length) + end = vTabs.length - 1; + selIndex = end + 1; + if (selIndex >= vTabs.length) + selIndex = start > 0 ? start - 1 : 0; + } + gb.mTabContainer.selectedItem = vTabs[selIndex]; + for (let i = end; i >= start; i--) { + remove(vTabs[i]); + } +} // }}} + // ============================================================================ // Mappings {{{ // ============================================================================ @@ -384,6 +443,14 @@ mappings.add([modes.NORMAL], ["<C-S-p>"], function (count) { switchToGroup("-" + (count || 1), true); }, { count: true }); +// overwrite 'd' +mappings.getDefault(modes.NORMAL, "d").action = function(count) { + removeTab(tabs.getTab(), count, false, 0); +}; +// overwrite 'D' +mappings.getDefault(modes.NORMAL, "D").action = function(count) { + removeTab(tabs.getTab(), count, true, 0); +}; // overwrite 'g0", 'g^' mappings.getDefault(modes.NORMAL, "g0").action = function (count) { selectVisible(0); }; // overwrite 'g$' |