From d25b2c6fb08d06b87f7bbe69a1bcfecd351c7c7f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 26 Mar 2016 09:15:44 +0000 Subject: Unified approach to repeat background command. --- background_scripts/main.coffee | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'background_scripts/main.coffee') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 01a82a37..04accd52 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -175,6 +175,10 @@ selectSpecificTab = (request) -> chrome.windows.update(tab.windowId, { focused: true }) chrome.tabs.update(request.id, { selected: true })) +repeatCommand = (command) -> (request) -> + if 0 < request.count-- + command request, (request) -> (repeatCommand command) request + moveTab = ({count, tab, registryEntry}) -> count = -count if registryEntry.command == "moveTabLeft" chrome.tabs.getAllInWindow null, (tabs) -> @@ -189,7 +193,7 @@ moveTab = ({count, tab, registryEntry}) -> # These are commands which are bound to keystroke which must be handled by the background page. They are # mapped in commands.coffee. BackgroundCommands = - createTab: (request) -> + createTab: repeatCommand (request, callback) -> request.url ?= do -> url = Settings.get "newTabUrl" if url == "pages/blank.html" @@ -197,11 +201,9 @@ BackgroundCommands = if request.tab.incognito then "chrome://newtab" else chrome.runtime.getURL newTabUrl else url - if 0 < request.count-- - TabOperations.openUrlInNewTab request, (tab) => @createTab extend request, {tab, tabId: tab.id} - duplicateTab: (request) -> - if 0 < request.count-- - chrome.tabs.duplicate request.tabId, (tab) => @duplicateTab extend request, {tab, tabId: tab.id} + TabOperations.openUrlInNewTab request, (tab) -> callback extend request, {tab, tabId: tab.id} + duplicateTab: repeatCommand (request, callback) -> + chrome.tabs.duplicate request.tabId, (tab) -> callback extend request, {tab, tabId: tab.id} moveTabToNewWindow: ({count, tab}) -> chrome.tabs.query {currentWindow: true}, (tabs) -> activeTabIndex = tab.index @@ -218,9 +220,7 @@ BackgroundCommands = activeTabIndex = tab.index startTabIndex = Math.max 0, Math.min activeTabIndex, tabs.length - count chrome.tabs.remove (tab.id for tab in tabs[startTabIndex...startTabIndex + count]) - restoreTab: (request) -> - if 0 < request.count-- - chrome.sessions.restore null, => @restoreTab request + restoreTab: repeatCommand (request, callback) -> chrome.sessions.restore null, callback request openCopiedUrlInCurrentTab: (request) -> TabOperations.openUrlInCurrentTab extend request, url: Clipboard.paste() openCopiedUrlInNewTab: (request) -> @createTab extend request, url: Clipboard.paste() togglePinTab: ({tab}) -> chrome.tabs.update tab.id, {pinned: !tab.pinned} -- cgit v1.2.3