From 3e734271ce45cdfd0235057b7a3c2f19e523a9c4 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 13 May 2014 16:38:46 +0100 Subject: Fix implementation of and add repetition to moveTabLeft and moveTabRight commands This fixes #1056. --- background_scripts/main.coffee | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 666c37e0..0511303a 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -219,7 +219,9 @@ repeatFunction = (func, totalCount, currentCount, frameId) -> moveTab = (callback, direction) -> chrome.tabs.getSelected(null, (tab) -> - chrome.tabs.move(tab.id, {index: tab.index + direction }, callback)) + # Use Math.max to prevent -1 as the new index, otherwise the tab of index n will wrap to the far RHS when + # moved left by exactly (n+1) places. + chrome.tabs.move(tab.id, {index: Math.max(0, tab.index + direction) }, callback)) # Start action functions @@ -238,8 +240,6 @@ BackgroundCommands = previousTab: (callback) -> selectTab(callback, "previous") firstTab: (callback) -> selectTab(callback, "first") lastTab: (callback) -> selectTab(callback, "last") - moveTabLeft: (callback) -> moveTab(callback, -1) - moveTabRight: (callback) -> moveTab(callback, 1) removeTab: -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.remove(tab.id)) @@ -275,6 +275,8 @@ BackgroundCommands = chrome.tabs.getSelected(null, (tab) -> chrome.tabs.sendMessage(tab.id, { name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId })) + moveTabLeft: (count) -> moveTab(null, -count) + moveTabRight: (count) -> moveTab(null, count) nextFrame: (count) -> chrome.tabs.getSelected(null, (tab) -> frames = framesForTab[tab.id].frames -- cgit v1.2.3