aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions/index.js17
-rw-r--r--src/background/index.js7
-rw-r--r--src/background/key-queue.js21
-rw-r--r--src/content/index.js50
-rw-r--r--src/reducers/content.js48
-rw-r--r--src/shared/actions.js31
6 files changed, 80 insertions, 94 deletions
diff --git a/src/actions/index.js b/src/actions/index.js
index bc44fec..de3ab42 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -1,11 +1,12 @@
export default {
+ // console commands
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',
+ // Background commands
BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions',
-
TABS_CLOSE: 'tabs.close',
TABS_REOPEN: 'tabs.reopen',
TABS_PREV: 'tabs.prev',
@@ -14,4 +15,18 @@ export default {
ZOOM_IN: 'zoom.in',
ZOOM_OUT: 'zoom.out',
ZOOM_NEUTRAL: 'zoom.neutral',
+
+ // content commands
+ CMD_OPEN: 'cmd.open',
+ CMD_TABS_OPEN: 'cmd.tabs.open',
+ CMD_BUFFER: 'cmd.buffer',
+ SCROLL_LINES: 'scroll.lines',
+ SCROLL_PAGES: 'scroll.pages',
+ SCROLL_TOP: 'scroll.top',
+ SCROLL_BOTTOM: 'scroll.bottom',
+ SCROLL_LEFT: 'scroll.left',
+ SCROLL_RIGHT: 'scroll.right',
+ FOLLOW_START: 'follow.start',
+ HISTORY_PREV: 'history.prev',
+ HISTORY_NEXT: 'history.next',
};
diff --git a/src/background/index.js b/src/background/index.js
index cb7a3ff..3fa8553 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -1,4 +1,3 @@
-import * as actions from '../shared/actions';
import * as tabs from './tabs';
import KeyQueue from './key-queue';
import backgroundReducers from '../reducers/background';
@@ -14,11 +13,9 @@ const keyPressHandle = (request, sender) => {
return Promise.resolve();
}
- if (actions.isContentAction(action.type)) {
+ return backgroundReducers(undefined, action, sender).then(() => {
return browser.tabs.sendMessage(sender.tab.id, action);
- } else {
- return backgroundReducers(undefined, action, sender);
- }
+ });
};
const normalizeUrl = (string) => {
diff --git a/src/background/key-queue.js b/src/background/key-queue.js
index 25f1d24..924bf77 100644
--- a/src/background/key-queue.js
+++ b/src/background/key-queue.js
@@ -1,5 +1,4 @@
-import newActions from '../actions';
-import * as actions from '../shared/actions';
+import actions from '../actions';
const DEFAULT_KEYMAP = {
':': { type: actions.CMD_OPEN },
@@ -18,15 +17,15 @@ const DEFAULT_KEYMAP = {
'G': { type: actions.SCROLL_BOTTOM },
'0': { type: actions.SCROLL_LEFT },
'$': { type: actions.SCROLL_RIGHT },
- 'd': { type: newActions.TABS_CLOSE },
- 'u': { type: newActions.TABS_REOPEN },
- 'h': { type: newActions.TABS_PREV, count: 1 },
- 'l': { type: newActions.TABS_NEXT, count: 1 },
- 'r': { type: newActions.TABS_RELOAD, cache: false },
- 'R': { type: newActions.TABS_RELOAD, cache: true },
- 'zi': { type: newActions.ZOOM_IN },
- 'zo': { type: newActions.ZOOM_OUT },
- 'zz': { type: newActions.ZOOM_NEUTRAL },
+ 'd': { type: actions.TABS_CLOSE },
+ 'u': { type: actions.TABS_REOPEN },
+ 'h': { type: actions.TABS_PREV, count: 1 },
+ 'l': { type: actions.TABS_NEXT, count: 1 },
+ 'r': { type: actions.TABS_RELOAD, cache: false },
+ 'R': { type: actions.TABS_RELOAD, cache: true },
+ 'zi': { type: actions.ZOOM_IN },
+ 'zo': { type: actions.ZOOM_OUT },
+ 'zz': { type: actions.ZOOM_NEUTRAL },
'f': { type: actions.FOLLOW_START, newTab: false },
'F': { type: actions.FOLLOW_START, newTab: true },
'H': { type: actions.HISTORY_PREV },
diff --git a/src/content/index.js b/src/content/index.js
index 4fba516..314dfea 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,54 +1,12 @@
import '../console/console-frame.scss';
-import * as scrolls from './scrolls';
-import * as histories from './histories';
-import * as actions from '../shared/actions';
import * as consoleFrames from '../console/frames';
-import actionTypes from '../actions';
-import Follow from './follow';
+import actions from '../actions';
+import contentReducer from '../reducers/content';
consoleFrames.initialize(window.document);
browser.runtime.onMessage.addListener((action) => {
- switch (action.type) {
- case actions.CMD_OPEN:
- return consoleFrames.showCommand('');
- case actions.CMD_TABS_OPEN:
- if (action.alter) {
- // alter url
- return consoleFrames.showCommand('open ' + window.location.href);
- } else {
- return consoleFrames.showCommand('open ');
- }
- case actions.CMD_BUFFER:
- return consoleFrames.showCommand('buffer ');
- case actions.SCROLL_LINES:
- scrolls.scrollLines(window, action.count);
- break;
- case actions.SCROLL_PAGES:
- scrolls.scrollPages(window, action.count);
- break;
- case actions.SCROLL_TOP:
- scrolls.scrollTop(window);
- break;
- case actions.SCROLL_BOTTOM:
- scrolls.scrollBottom(window);
- break;
- case actions.SCROLL_LEFT:
- scrolls.scrollLeft(window);
- break;
- case actions.SCROLL_RIGHT:
- scrolls.scrollRight(window);
- break;
- case actions.FOLLOW_START:
- new Follow(window.document, action.newTab);
- break;
- case actions.HISTORY_PREV:
- histories.prev(window);
- break;
- case actions.HISTORY_NEXT:
- histories.next(window);
- break;
- }
+ contentReducer(undefined, action);
return Promise.resolve();
});
@@ -72,7 +30,7 @@ window.addEventListener("keypress", (e) => {
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
- case actionTypes.CONSOLE_HIDE:
+ case actions.CONSOLE_HIDE:
window.focus();
return consoleFrames.blur(window.document);
case 'vimvixen.command.enter':
diff --git a/src/reducers/content.js b/src/reducers/content.js
new file mode 100644
index 0000000..bcf1160
--- /dev/null
+++ b/src/reducers/content.js
@@ -0,0 +1,48 @@
+import * as consoleFrames from '../console/frames';
+import * as histories from '../content/histories';
+import * as scrolls from '../content/scrolls';
+import Follow from '../content/follow';
+import actions from '../actions';
+
+export default function reducer(state, action = {}) {
+ switch (action.type) {
+ case actions.CMD_OPEN:
+ return consoleFrames.showCommand('');
+ case actions.CMD_TABS_OPEN:
+ if (action.alter) {
+ // alter url
+ return consoleFrames.showCommand('open ' + window.location.href);
+ } else {
+ return consoleFrames.showCommand('open ');
+ }
+ case actions.CMD_BUFFER:
+ return consoleFrames.showCommand('buffer ');
+ case actions.SCROLL_LINES:
+ scrolls.scrollLines(window, action.count);
+ break;
+ case actions.SCROLL_PAGES:
+ scrolls.scrollPages(window, action.count);
+ break;
+ case actions.SCROLL_TOP:
+ scrolls.scrollTop(window);
+ break;
+ case actions.SCROLL_BOTTOM:
+ scrolls.scrollBottom(window);
+ break;
+ case actions.SCROLL_LEFT:
+ scrolls.scrollLeft(window);
+ break;
+ case actions.SCROLL_RIGHT:
+ scrolls.scrollRight(window);
+ break;
+ case actions.FOLLOW_START:
+ new Follow(window.document, action.newTab);
+ break;
+ case actions.HISTORY_PREV:
+ histories.prev(window);
+ break;
+ case actions.HISTORY_NEXT:
+ histories.next(window);
+ break;
+ }
+}
diff --git a/src/shared/actions.js b/src/shared/actions.js
deleted file mode 100644
index 5163cf3..0000000
--- a/src/shared/actions.js
+++ /dev/null
@@ -1,31 +0,0 @@
-export const CMD_OPEN = 'cmd.open';
-export const CMD_TABS_OPEN = 'cmd.tabs.open';
-export const CMD_BUFFER = 'cmd.buffer';
-export const SCROLL_LINES = 'scroll.lines';
-export const SCROLL_PAGES = 'scroll.pages';
-export const SCROLL_TOP = 'scroll.top';
-export const SCROLL_BOTTOM = 'scroll.bottom';
-export const SCROLL_LEFT= 'scroll.left';
-export const SCROLL_RIGHT= 'scroll.right';
-export const FOLLOW_START = 'follow.start';
-export const HISTORY_PREV = 'history.prev';
-export const HISTORY_NEXT = 'history.next';
-
-const CONTENT_ACTION_SET = new Set([
- CMD_OPEN,
- CMD_TABS_OPEN,
- CMD_BUFFER,
- SCROLL_LINES,
- SCROLL_PAGES,
- SCROLL_TOP,
- SCROLL_BOTTOM,
- SCROLL_LEFT,
- SCROLL_RIGHT,
- FOLLOW_START,
- HISTORY_PREV,
- HISTORY_NEXT
-]);
-
-export const isContentAction = (action) => {
- return CONTENT_ACTION_SET.has(action);
-};