diff options
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/actions/operation.js | 4 | ||||
-rw-r--r-- | src/background/tabs.js | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js index 1e4990c..1188ea2 100644 --- a/src/background/actions/operation.js +++ b/src/background/actions/operation.js @@ -17,6 +17,8 @@ const exec = (operation, tab) => { switch (operation.type) { case operations.TAB_CLOSE: return tabs.closeTab(tab.id); + case operations.TAB_CLOSE_FORCE: + return tabs.closeTabForce(tab.id); case operations.TAB_REOPEN: return tabs.reopenTab(); case operations.TAB_PREV: @@ -27,6 +29,8 @@ const exec = (operation, tab) => { return tabs.selectFirstTab(); case operations.TAB_LAST: return tabs.selectLastTab(); + case operations.TAB_PREV_SEL: + return tabs.selectPrevSelTab(); case operations.TAB_RELOAD: return tabs.reload(tab, operation.cache); case operations.TAB_PIN: diff --git a/src/background/tabs.js b/src/background/tabs.js index b34f7c2..e939870 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -1,4 +1,22 @@ +let prevSelTab = 1; +let currSelTab = 1; + +browser.tabs.onActivated.addListener((activeInfo) => { + return browser.tabs.query({ currentWindow: true }).then(() => { + prevSelTab = currSelTab; + currSelTab = activeInfo.tabId; + }); +}); + const closeTab = (id) => { + return browser.tabs.get(id).then((tab) => { + if (!tab.pinned) { + return browser.tabs.remove(id); + } + }); +}; + +const closeTabForce = (id) => { return browser.tabs.remove(id); }; @@ -93,6 +111,10 @@ const selectLastTab = () => { }); }; +const selectPrevSelTab = () => { + return browser.tabs.update(prevSelTab, { active: true }); +}; + const reload = (current, cache) => { return browser.tabs.reload( current.id, @@ -116,7 +138,8 @@ const duplicate = (id) => { }; export { - closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, - selectPrevTab, selectNextTab, selectFirstTab, selectLastTab, reload, - updateTabPinned, toggleTabPinned, duplicate + closeTab, closeTabForce, reopenTab, selectAt, selectByKeyword, + getCompletions, selectPrevTab, selectNextTab, selectFirstTab, + selectLastTab, selectPrevSelTab, reload, updateTabPinned, + toggleTabPinned, duplicate }; |