From 91bbb3122b58e834cc5512768eb09046fac2b448 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 10 Jun 2015 18:23:40 +0100 Subject: Re-work tabMoveLeft/Right. Note. This does not allow tabs to rotate from the left around to the right, or vice versa. Which means "999<<" moves the current tab all the way to the left (and similarly to the right). Fixes #1727 (kind of). --- background_scripts/main.coffee | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 835b8a9a..6e1226b6 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -237,11 +237,11 @@ repeatFunction = (func, totalCount, currentCount, frameId) -> -> repeatFunction(func, totalCount, currentCount + 1, frameId), frameId) -moveTab = (callback, direction) -> - chrome.tabs.getSelected(null, (tab) -> - # 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)) +moveTab = (count) -> + chrome.tabs.getAllInWindow null, (tabs) -> + chrome.tabs.getSelected null, (tab) -> + chrome.tabs.move tab.id, + index: Math.max 0, Math.min tabs.length - 1, tab.index + count # Start action functions @@ -304,8 +304,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) + moveTabLeft: (count) -> moveTab -count + moveTabRight: (count) -> moveTab count nextFrame: (count,frameId) -> chrome.tabs.getSelected null, (tab) -> frameIdsForTab[tab.id] = cycleToFrame frameIdsForTab[tab.id], frameId, count -- cgit v1.2.3 From 30cfcbdcfaecf03de67561ae88574fac837f75e3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 10 Jun 2015 19:21:41 +0100 Subject: Do not try to move a tab to the left of pinned tabs. --- background_scripts/main.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 6e1226b6..272c3aa6 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -239,9 +239,12 @@ repeatFunction = (func, totalCount, currentCount, frameId) -> moveTab = (count) -> chrome.tabs.getAllInWindow null, (tabs) -> + pinnedCount = 0 + for tab in tabs + pinnedCount += 1 if tab.pinned chrome.tabs.getSelected null, (tab) -> chrome.tabs.move tab.id, - index: Math.max 0, Math.min tabs.length - 1, tab.index + count + index: Math.max pinnedCount, Math.min tabs.length - 1, tab.index + count # Start action functions -- cgit v1.2.3 From abc24123a9bec8f07d019d31c08a8740e695401d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 10 Jun 2015 20:01:12 +0100 Subject: Refactor moveTab for clarity... ... as suggested by @mrmr1993 in #1728. --- background_scripts/main.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 272c3aa6..d4b14f3c 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -239,9 +239,7 @@ repeatFunction = (func, totalCount, currentCount, frameId) -> moveTab = (count) -> chrome.tabs.getAllInWindow null, (tabs) -> - pinnedCount = 0 - for tab in tabs - pinnedCount += 1 if tab.pinned + pinnedCount = (tabs.filter (tab) -> tab.pinned).length chrome.tabs.getSelected null, (tab) -> chrome.tabs.move tab.id, index: Math.max pinnedCount, Math.min tabs.length - 1, tab.index + count -- cgit v1.2.3