aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background/index.js16
-rw-r--r--src/background/tabs.js11
-rw-r--r--src/console/console-frame.js5
-rw-r--r--src/content/index.js26
4 files changed, 47 insertions, 11 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 };
diff --git a/src/console/console-frame.js b/src/console/console-frame.js
index 11c36f4..e6bf3f5 100644
--- a/src/console/console-frame.js
+++ b/src/console/console-frame.js
@@ -53,6 +53,9 @@ export default class ConsoleFrame {
}
setCompletions(completions) {
- messages.send(this.element.contentWindow, completions);
+ messages.send(this.element.contentWindow, {
+ type: 'vimvixen.console.set.completions',
+ completions: completions
+ });
}
}
diff --git a/src/content/index.js b/src/content/index.js
index 8b3eb58..e682a7f 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -83,11 +83,27 @@ window.addEventListener("keypress", (e) => {
browser.runtime.sendMessage(request)
.then(handleResponse)
.catch((err) => {
+ console.error("Vim Vixen:", err);
vvConsole.showError(err.message);
- console.log(`Vim Vixen: ${err}`);
});
});
+const doCompletion = (line) => {
+ if (line.startsWith('buffer ')) {
+ let keyword = line.replace('buffer ', '');
+
+ browser.runtime.sendMessage({
+ type: 'event.cmd.tabs.completion',
+ text: keyword
+ }).then((completions) => {
+ vvConsole.setCompletions([completions]);
+ }).catch((e) => {
+ console.error("Vim Vixen:", err);
+ vvConsole.showError(e.message);
+ });
+ }
+};
+
messages.receive(window, (message) => {
switch (message.type) {
case 'vimvixen.command.blur':
@@ -100,16 +116,12 @@ messages.receive(window, (message) => {
type: 'event.cmd.enter',
text: message.value
}).catch((e) => {
+ console.error("Vim Vixen:", err);
vvConsole.showError(e.message);
});
break;
case 'vimvixen.command.change':
- browser.runtime.sendMessage({
- type: 'event.cmd.suggest',
- text: message.value
- }).catch((e) => {
- vvConsole.showError(e.message);
- });
+ doCompletion(message.value);
break;
default:
return;