aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background/presenters/tab.js12
-rw-r--r--src/background/usecases/command.js18
-rw-r--r--src/background/usecases/completions.js46
-rw-r--r--src/console/site.scss2
4 files changed, 62 insertions, 16 deletions
diff --git a/src/background/presenters/tab.js b/src/background/presenters/tab.js
index 6ad9736..bacb644 100644
--- a/src/background/presenters/tab.js
+++ b/src/background/presenters/tab.js
@@ -46,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);
}
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();
diff --git a/src/background/usecases/completions.js b/src/background/usecases/completions.js
index 2bf5b3b..af7aaf2 100644
--- a/src/background/usecases/completions.js
+++ b/src/background/usecases/completions.js
@@ -5,12 +5,14 @@ import CommandDocs from '../domains/command-docs';
import CompletionRepository from '../repositories/completions';
import * as filters from './filters';
import SettingRepository from '../repositories/setting';
+import TabPresenter from '../presenters/tab';
import * as properties from '../../shared/settings/properties';
const COMPLETION_ITEM_LIMIT = 10;
export default class CompletionsInteractor {
constructor() {
+ this.tabPresenter = new TabPresenter();
this.completionRepository = new CompletionRepository();
this.settingRepository = new SettingRepository();
}
@@ -50,8 +52,48 @@ export default class CompletionsInteractor {
return new Completions(groups);
}
- queryBuffer(name, keywords) {
- return this.queryTabs(name, false, keywords);
+ // eslint-disable-next-line max-statements
+ async queryBuffer(name, keywords) {
+ let lastId = await this.tabPresenter.getLastSelectedId();
+ let trimmed = keywords.trim();
+ let tabs = [];
+ if (trimmed.length > 0 && !isNaN(trimmed)) {
+ let all = await this.tabPresenter.getAll();
+ let index = parseInt(trimmed, 10) - 1;
+ if (index >= 0 && index < all.length) {
+ tabs = [all[index]];
+ }
+ } else if (trimmed === '%') {
+ let all = await this.tabPresenter.getAll();
+ let tab = all.find(t => t.active);
+ tabs = [tab];
+ } else if (trimmed === '#') {
+ if (typeof lastId !== 'undefined' && lastId !== null) {
+ let all = await this.tabPresenter.getAll();
+ let tab = all.find(t => t.id === lastId);
+ tabs = [tab];
+ }
+ } else {
+ tabs = await this.completionRepository.queryTabs(keywords, false);
+ }
+ const flag = (tab) => {
+ if (tab.active) {
+ return '%';
+ } else if (tab.id === lastId) {
+ return '#';
+ }
+ return ' ';
+ };
+ let items = tabs.map(tab => new CompletionItem({
+ caption: tab.index + 1 + ': ' + flag(tab) + ' ' + tab.title,
+ content: name + ' ' + tab.title,
+ url: tab.url,
+ icon: tab.favIconUrl
+ }));
+ if (items.length === 0) {
+ return Promise.resolve(Completions.empty());
+ }
+ return new Completions([new CompletionGroup('Buffers', items)]);
}
queryBdelete(name, keywords) {
diff --git a/src/console/site.scss b/src/console/site.scss
index cb89e50..b9b1016 100644
--- a/src/console/site.scss
+++ b/src/console/site.scss
@@ -44,7 +44,7 @@ body {
background-position: 0 center;
background-size: contain;
background-repeat: no-repeat;
- white-space: nowrap;
+ white-space: pre;
&.vimvixen-completion-selected {
background-color: yellow;