From ee740a8fc0995bc16eff9af1b317f75ada7164b5 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 9 Oct 2007 13:50:13 +0000 Subject: [PATCH] merge count support for deleting buffers --- NEWS | 1 + TODO | 1 - content/commands.js | 3 ++- content/mappings.js | 6 ++++-- content/tabs.js | 37 +++++++++++++++++++++++++++++++++---- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 7ca2dbaa..a9e9f3fb 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ * version 0.5.2 * added "s" and "a" mappings to extended hints mode for saving hint targets + * "d", "D" and :bdelete support count now * :back/:forward can use tabcompletion * :undoall support, and tabcompletion for :undo * new :redraw and Ctrl-L commands for forced redrawing of the screen diff --git a/TODO b/TODO index b756c719..8f0a7b27 100644 --- a/TODO +++ b/TODO @@ -24,7 +24,6 @@ FEATURES: 8 middleclick in content == p, and if command line is open, paste there the clipboard buffer 7 [ctrl-o/i] to Go back to a Previous Position (done partly, however currenty does not use a per tab jumplist) 7 whereever possible: get rid of dialogs and ask console-like dialog questions or write error prompts directly on the webpage or with :echo() -7 3d should delete 3 tabs 6 downloading of links to filesystem (:save ) 6 autocommands (BrowserStart, BrowserQuit, TabClose, TabOpen, TabChanged, PageLoaded, any more?) 6 vim like mappings for caret mode and textboxes (i to start caret mode?) diff --git a/content/commands.js b/content/commands.js index 51345c44..35ebeb41 100644 --- a/content/commands.js +++ b/content/commands.js @@ -282,7 +282,8 @@ function Commands() //{{{ { usage: ["[count]bd[elete][!]"], short_help: "Delete current buffer (=tab)", - help: "Count WILL be supported in future releases, then :2bd removes two tabs and the one to the right is selected.
Do :bdelete! to select the tab to the left after removing the current tab." + help: "Count is supported, :2bd removes two tabs and the one to the right is selected. " + + "Do :bdelete! to select the tab to the left after removing the current tab." } )); addDefaultCommand(new Command(["beep"], diff --git a/content/mappings.js b/content/mappings.js index 598828a7..80c3100a 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -386,7 +386,8 @@ function Mappings() //{{{ function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); }, { short_help: "Delete current buffer (=tab)", - help: "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", + help: "Count is supported, 2d removes the current and next tab and the one to the right is selected. " + + "Does not wrap if [count] is larger than available tabs to the right.", flags: Mappings.flags.COUNT } )); @@ -394,7 +395,8 @@ function Mappings() //{{{ function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, true, 0); }, { short_help: "Delete current buffer (=tab)", - help: "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", + help: "Count is supported, 2D removes the current and previous tab and the one to the left is selected. " + + "Does not wrap if [count] is larger than available tabs to the left.", flags: Mappings.flags.COUNT } )); diff --git a/content/tabs.js b/content/tabs.js index 978b21fb..37b75f78 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -151,15 +151,44 @@ function Tabs() //{{{ */ this.remove = function(tab, count, focus_left_tab, quit_on_last_tab) { - if (count < 1) count = 1; + function removeOrBlankTab (tab) + { + if (getBrowser().mTabs.length > 1) + getBrowser().removeTab(tab); + else + { + vimperator.open("about:blank", vimperator.NEW_BACKGROUND_TAB); + getBrowser().removeTab(tab); + } + } + + if (count < 1) + count = 1; if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count) vimperator.quit(quit_on_last_tab == 2); - if (focus_left_tab && tab.previousSibling) - this.select("-1", false); - getBrowser().removeTab(tab); + var index = this.index(tab); + if (focus_left_tab) + { + var last_removed_tab = 0; + for (var i = index; i > index - count && i >= 0; i--) + { + removeOrBlankTab(this.getTab(i)); + last_removed_tab = i > 0 ? i : 1; + } + getBrowser().mTabContainer.selectedIndex = last_removed_tab - 1; + } + else + { + var i = index + count - 1; + if (i >= this.count()) + i = this.count() - 1; + + for (; i >= index; i--) + removeOrBlankTab(this.getTab(i)); + } } this.keepOnly = function(tab)