aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions/background.js11
-rw-r--r--src/actions/index.js4
-rw-r--r--src/background/index.js20
-rw-r--r--src/console/console-frame.js4
-rw-r--r--src/console/console.js12
-rw-r--r--src/content/index.js19
-rw-r--r--src/reducers/background.js38
7 files changed, 61 insertions, 47 deletions
diff --git a/src/actions/background.js b/src/actions/background.js
new file mode 100644
index 0000000..40b901b
--- /dev/null
+++ b/src/actions/background.js
@@ -0,0 +1,11 @@
+import actions from '../actions';
+
+export function requestCompletions(line) {
+ let command = line.split(' ', 1)[0];
+ let keywords = line.replace(command + ' ', '');
+ return {
+ type: actions.BACKGROUND_REQUEST_COMPLETIONS,
+ command,
+ keywords
+ };
+}
diff --git a/src/actions/index.js b/src/actions/index.js
index 38ced9d..8f22193 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -2,5 +2,7 @@ export default {
CONSOLE_SHOW_COMMAND: 'vimvixen.console.show.command',
CONSOLE_SET_COMPLETIONS: 'vimvixen.console.set.completions',
CONSOLE_SHOW_ERROR: 'vimvixen.console.show.error',
- CONSOLE_HIDE: 'vimvixen.console.hide'
+ CONSOLE_HIDE: 'vimvixen.console.hide',
+
+ BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions'
};
diff --git a/src/background/index.js b/src/background/index.js
index 61d4895..a80d1ea 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -2,6 +2,7 @@ import * as actions from '../shared/actions';
import * as tabs from './tabs';
import * as zooms from './zooms';
import KeyQueue from './key-queue';
+import backgroundReducers from '../reducers/background';
const queue = new KeyQueue();
@@ -81,22 +82,11 @@ browser.runtime.onMessage.addListener((request, sender) => {
return keyPressHandle(request, sender);
case 'event.cmd.enter':
return cmdEnterHandle(request, sender);
- 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,
- icon: tab.favIconUrl
- }
- });
- return {
- name: "Buffers",
- items: items
- };
- });
default:
return browser.tabs.sendMessage(sender.tab.id, request);
}
});
+
+browser.runtime.onMessage.addListener((action, sender) => {
+ return backgroundReducers(undefined, action, sender.tab.id);
+});
diff --git a/src/console/console-frame.js b/src/console/console-frame.js
index 8b4c17a..063026c 100644
--- a/src/console/console-frame.js
+++ b/src/console/console-frame.js
@@ -45,8 +45,4 @@ export default class ConsoleFrame {
isErrorShown() {
return this.element.style.display === 'block' && this.errorShown;
}
-
- setCompletions(completions) {
- return browser.runtime.sendMessage(consoleActions.setCompletions(completions));
- }
}
diff --git a/src/console/console.js b/src/console/console.js
index 35d98e0..d79e154 100644
--- a/src/console/console.js
+++ b/src/console/console.js
@@ -1,4 +1,5 @@
import './console.scss';
+import * as backgroundActions from '../actions/background';
import Completion from './completion';
import consoleReducer from '../reducers/console';
@@ -21,13 +22,6 @@ const keydownMessage = (input) => {
};
};
-const keyupMessage = (input) => {
- return {
- type: 'vimvixen.command.change',
- value: input.value
- };
-};
-
const handleBlur = () => {
return browser.runtime.sendMessage(blurMessage());
};
@@ -88,7 +82,9 @@ const handleKeyup = (e) => {
return;
}
prevValue = e.target.value;
- return browser.runtime.sendMessage(keyupMessage(e.target));
+ return browser.runtime.sendMessage(
+ backgroundActions.requestCompletions(e.target.value)
+ );
};
window.addEventListener('load', () => {
diff --git a/src/content/index.js b/src/content/index.js
index deb3506..1a7fa55 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -68,23 +68,6 @@ window.addEventListener("keypress", (e) => {
});
});
-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((err) => {
- console.error("Vim Vixen:", err);
- vvConsole.showError(err.message);
- });
- }
- return Promise.resolve();
-};
-
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case 'vimvixen.command.blur':
@@ -100,8 +83,6 @@ browser.runtime.onMessage.addListener((action) => {
console.error("Vim Vixen:", err);
vvConsole.showError(err.message);
});
- case 'vimvixen.command.change':
- return doCompletion(action.value);
default:
return Promise.resolve();
}
diff --git a/src/reducers/background.js b/src/reducers/background.js
new file mode 100644
index 0000000..eccc8ca
--- /dev/null
+++ b/src/reducers/background.js
@@ -0,0 +1,38 @@
+import * as tabs from '../background/tabs';
+import * as consoleActions from '../actions/console';
+import actions from '../actions';
+
+const doCompletion = (command, keywords, sendto) => {
+ if (command === 'buffer') {
+ return tabs.getCompletions(keywords).then((tabs) => {
+ let items = tabs.map((tab) => {
+ return {
+ caption: tab.title,
+ content: tab.title,
+ url: tab.url,
+ icon: tab.favIconUrl
+ }
+ });
+ let completions = {
+ name: "Buffers",
+ items: items
+ };
+ return browser.tabs.sendMessage(
+ sendto,
+ consoleActions.setCompletions([completions]));
+ });
+ }
+ return Promise.resolve();
+};
+
+
+
+export default function reducer(state, action = {}, sendto) {
+ // TODO hide sendto object
+ switch (action.type) {
+ case actions.BACKGROUND_REQUEST_COMPLETIONS:
+ return doCompletion(action.command, action.keywords, sendto);
+ default:
+ return Promise.resolve();
+ }
+}