aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/index.js16
-rw-r--r--src/background/tabs.js11
2 files changed, 24 insertions, 3 deletions
diff --git a/src/background/index.js b/src/background/index.js
index 93d0e74..4a5e6d6 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -84,8 +84,20 @@ browser.runtime.onMessage.addListener((request, sender) => {
return keyPressHandle(request, sender);
case 'event.cmd.enter':
return cmdEnterHandle(request, sender);
- case 'event.cmd.suggest':
- // TODO make suggestion and return
+ case 'event.cmd.tabs.completion':
+ return tabs.getCompletions(request.text).then((tabs) => {
+ let items = tabs.map((tab) => {
+ return {
+ caption: tab.title,
+ content: tab.title,
+ url: tab.url
+ }
+ });
+ return {
+ name: "Buffers",
+ items: items
+ };
+ });
break;
}
return Promise.resolve();
diff --git a/src/background/tabs.js b/src/background/tabs.js
index be8ef02..111bbd9 100644
--- a/src/background/tabs.js
+++ b/src/background/tabs.js
@@ -49,6 +49,15 @@ const selectByKeyword = (current, keyword) => {
});
}
+const getCompletions = (keyword) => {
+ return browser.tabs.query({ currentWindow: true }).then((tabs) => {
+ let matched = tabs.filter((t) => {
+ return t.url.includes(keyword) || t.title.includes(keyword)
+ })
+ return matched;
+ });
+};
+
const selectPrevTab = (current, count) => {
return browser.tabs.query({ currentWindow: true }, (tabs) => {
if (tabs.length < 2) {
@@ -78,4 +87,4 @@ const reload = (current, cache) => {
);
};
-export { closeTab, reopenTab, selectAt, selectByKeyword, selectNextTab, selectPrevTab, reload };
+export { closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, selectPrevTab, selectNextTab, reload };