From eb4086e1529af4ddaf1d1f1c4262b111462a5739 Mon Sep 17 00:00:00 2001 From: Wang Zhuochun Date: Thu, 11 Sep 2014 23:33:52 +0800 Subject: [PATCH] Add count support to tab switching commands - It wraps when count = 1, the same as the original behaviour. - It goes to the first or last tab when count exceeds boundary. --- extension/packages/commands.coffee | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/extension/packages/commands.coffee b/extension/packages/commands.coffee index dd84fc4..191abe3 100644 --- a/extension/packages/commands.coffee +++ b/extension/packages/commands.coffee @@ -139,15 +139,25 @@ command_scroll_page_up = (vim, event, count) -> command_open_tab = (vim) -> vim.rootWindow.BrowserOpenTab() +helper_switch_tab = (direction, vim, event, count) -> + gBrowser = vim.rootWindow.gBrowser + + if count == 1 + gBrowser.tabContainer.advanceSelectedTab(direction, wrap = true) + else + currentIndex = gBrowser.visibleTabs.indexOf(gBrowser.selectedTab) + + targetIndex = currentIndex + count * direction + targetIndex = Math.max(0, targetIndex) + targetIndex = Math.min(targetIndex, gBrowser.visibleTabs.length - 1) + + gBrowser.selectTabAtIndex(targetIndex) + # Switch to the previous tab. -command_tab_prev = (vim) -> - wrap = true - vim.rootWindow.gBrowser.tabContainer.advanceSelectedTab(-1, true) # wrap +command_tab_prev = helper_switch_tab.bind(undefined, -1) # Switch to the next tab. -command_tab_next = (vim) -> - wrap = true - vim.rootWindow.gBrowser.tabContainer.advanceSelectedTab(+1, true) # wrap +command_tab_next = helper_switch_tab.bind(undefined, +1) # Move the current tab backward. command_tab_move_left = (vim) -> -- 2.39.3