diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-29 13:34:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-29 13:34:10 +0900 |
commit | 8ea004f629021a0fb5fcbce9398f2cf2f952938a (patch) | |
tree | d35d37b1688aaf6a22389a6b761e2be2f98f85c7 /src/background/presenters | |
parent | 85e9b9da3714c0fa2998b0fab8f2a01c49d84d5a (diff) | |
parent | b3672f0ffd82148716b38d133f35a5f9d2706ba8 (diff) |
Merge pull request #442 from ueokande/search-on-paste
Buffer flags
Diffstat (limited to 'src/background/presenters')
-rw-r--r-- | src/background/presenters/tab.js | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/background/presenters/tab.js b/src/background/presenters/tab.js index 2a06a5a..bacb644 100644 --- a/src/background/presenters/tab.js +++ b/src/background/presenters/tab.js @@ -1,3 +1,8 @@ +import MemoryStorage from '../infrastructures/memory-storage'; + +const CURRENT_SELECTED_KEY = 'tabs.current.selected'; +const LAST_SELECTED_KEY = 'tabs.last.selected'; + export default class TabPresenter { open(url, tabId) { return browser.tabs.update(tabId, { url }); @@ -18,6 +23,15 @@ export default class TabPresenter { return browser.tabs.query({ currentWindow: true }); } + async getLastSelectedId() { + let cache = new MemoryStorage(); + let tabId = await cache.get(LAST_SELECTED_KEY); + if (tabId === null || typeof tabId === 'undefined') { + return; + } + return tabId; + } + async getByKeyword(keyword, excludePinned = false) { let tabs = await browser.tabs.query({ currentWindow: true }); return tabs.filter((t) => { @@ -32,18 +46,6 @@ export default class TabPresenter { return browser.tabs.update(tabId, { active: true }); } - async selectAt(index) { - let tabs = await browser.tabs.query({ currentWindow: true }); - if (tabs.length < 2) { - return; - } - if (index < 0 || tabs.length <= index) { - throw new RangeError(`tab ${index + 1} does not exist`); - } - let id = tabs[index].id; - return browser.tabs.update(id, { active: true }); - } - remove(ids) { return browser.tabs.remove(ids); } @@ -99,3 +101,14 @@ export default class TabPresenter { browser.tabs.onActivated.addListener(listener); } } + +let tabPresenter = new TabPresenter(); +tabPresenter.onSelected((tab) => { + let cache = new MemoryStorage(); + + let lastId = cache.get(CURRENT_SELECTED_KEY); + if (lastId) { + cache.set(LAST_SELECTED_KEY, lastId); + } + cache.set(CURRENT_SELECTED_KEY, tab.tabId); +}); |