diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-29 13:13:11 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-29 13:13:11 +0900 |
commit | b3672f0ffd82148716b38d133f35a5f9d2706ba8 (patch) | |
tree | 75a4edfdbd08aac4437d5e4c85331839b00b7c5a /src/background/usecases/command.js | |
parent | 0ca138cba46408388ee46eab16f46cec25cac41a (diff) |
Add buffer flags on buffer command and completion
Diffstat (limited to 'src/background/usecases/command.js')
-rw-r--r-- | src/background/usecases/command.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/background/usecases/command.js b/src/background/usecases/command.js index 7fd2e57..f6ade43 100644 --- a/src/background/usecases/command.js +++ b/src/background/usecases/command.js @@ -34,13 +34,29 @@ export default class CommandIndicator { return this.windowPresenter.create(url); } + // eslint-disable-next-line max-statements async buffer(keywords) { if (keywords.length === 0) { return; } + if (!isNaN(keywords)) { + let tabs = await this.tabPresenter.getAll(); let index = parseInt(keywords, 10) - 1; - return tabs.selectAt(index); + if (index < 0 || tabs.length <= index) { + throw new RangeError(`tab ${index + 1} does not exist`); + } + return this.tabPresenter.select(tabs[index].id); + } else if (keywords.trim() === '%') { + // Select current window + return; + } else if (keywords.trim() === '#') { + // Select last selected window + let lastId = await this.tabPresenter.getLastSelectedId(); + if (typeof lastId === 'undefined' || lastId === null) { + throw new Error('No last selected tab'); + } + return this.tabPresenter.select(lastId); } let current = await this.tabPresenter.getCurrent(); |