aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-13 21:55:09 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-13 21:55:09 +0900
commita61f37ad61da8766bf74d5a8b26e53390cb5b6c9 (patch)
treeffe92ab075915a0fd27bf9cde5dec5e4afcd1f66 /src
parentb6e5153c1f67a68434ad3db7d3726f129cc14aa4 (diff)
content operations
Diffstat (limited to 'src')
-rw-r--r--src/actions/index.js9
-rw-r--r--src/actions/operation.js5
-rw-r--r--src/background/index.js2
-rw-r--r--src/background/keys.js32
-rw-r--r--src/content/index.js30
-rw-r--r--src/operations/index.js11
-rw-r--r--src/reducers/background.js1
-rw-r--r--src/reducers/content.js30
8 files changed, 62 insertions, 58 deletions
diff --git a/src/actions/index.js b/src/actions/index.js
index ae29238..754b7f0 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -12,15 +12,6 @@ export default {
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',
// User input
INPUT_KEY_PRESS: 'input.key,press',
diff --git a/src/actions/operation.js b/src/actions/operation.js
index 4106076..352bfac 100644
--- a/src/actions/operation.js
+++ b/src/actions/operation.js
@@ -21,7 +21,10 @@ export function exec(operation, sender) {
case operations.ZOOM_NEUTRAL:
return zooms.neutral();
default:
- return Promise.resolve();
+ return browser.tabs.sendMessage(sender.tab.id, {
+ type: 'require.content.operation',
+ operation
+ });
}
}
diff --git a/src/background/index.js b/src/background/index.js
index ab99d39..0c3adce 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -6,7 +6,7 @@ import commandReducer from '../reducers/command';
import inputReducers from '../reducers/input';
import * as store from '../store'
-const emptyReducer = (state, action) => state;
+const emptyReducer = (state) => state;
const emptyStore = store.createStore(emptyReducer, (e) => {
console.error('Vim-Vixen:', e);
});
diff --git a/src/background/keys.js b/src/background/keys.js
index 72b333a..0f73bf0 100644
--- a/src/background/keys.js
+++ b/src/background/keys.js
@@ -6,18 +6,18 @@ const defaultKeymap = {
'o': { type: actions.CMD_TABS_OPEN, alter: false },
'O': { type: actions.CMD_TABS_OPEN, alter: true },
'b': { type: actions.CMD_BUFFER },
- 'k': { type: actions.SCROLL_LINES, count: -1 },
- 'j': { type: actions.SCROLL_LINES, count: 1 },
- '<C-E>': { type: actions.SCROLL_LINES, count: -1 },
- '<C-Y>': { type: actions.SCROLL_LINES, count: 1 },
- '<C-U>': { type: actions.SCROLL_PAGES, count: -0.5 },
- '<C-D>': { type: actions.SCROLL_PAGES, count: 0.5 },
- '<C-B>': { type: actions.SCROLL_PAGES, count: -1 },
- '<C-F>': { type: actions.SCROLL_PAGES, count: 1 },
- 'gg': { type: actions.SCROLL_TOP },
- 'G': { type: actions.SCROLL_BOTTOM },
- '0': { type: actions.SCROLL_LEFT },
- '$': { type: actions.SCROLL_RIGHT },
+ 'k': { type: operations.SCROLL_LINES, count: -1 },
+ 'j': { type: operations.SCROLL_LINES, count: 1 },
+ '<C-E>': { type: operations.SCROLL_LINES, count: -1 },
+ '<C-Y>': { type: operations.SCROLL_LINES, count: 1 },
+ '<C-U>': { type: operations.SCROLL_PAGES, count: -0.5 },
+ '<C-D>': { type: operations.SCROLL_PAGES, count: 0.5 },
+ '<C-B>': { type: operations.SCROLL_PAGES, count: -1 },
+ '<C-F>': { type: operations.SCROLL_PAGES, count: 1 },
+ 'gg': { type: operations.SCROLL_TOP },
+ 'G': { type: operations.SCROLL_BOTTOM },
+ '0': { type: operations.SCROLL_LEFT },
+ '$': { type: operations.SCROLL_RIGHT },
'd': { type: operations.TABS_CLOSE },
'u': { type: operations.TABS_REOPEN },
'h': { type: operations.TABS_PREV, count: 1 },
@@ -27,10 +27,10 @@ const defaultKeymap = {
'zi': { type: operations.ZOOM_IN },
'zo': { type: operations.ZOOM_OUT },
'zz': { type: operations.ZOOM_NEUTRAL },
- 'f': { type: actions.FOLLOW_START, newTab: false },
- 'F': { type: actions.FOLLOW_START, newTab: true },
- 'H': { type: actions.HISTORY_PREV },
- 'L': { type: actions.HISTORY_NEXT },
+ 'f': { type: operations.FOLLOW_START, newTab: false },
+ 'F': { type: operations.FOLLOW_START, newTab: true },
+ 'H': { type: operations.HISTORY_PREV },
+ 'L': { type: operations.HISTORY_NEXT },
}
const asKeymapChars = (keys) => {
diff --git a/src/content/index.js b/src/content/index.js
index 12d079f..1bba656 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,7 +1,11 @@
import '../console/console-frame.scss';
import * as inputActions from '../actions/input';
import * as consoleFrames from '../console/frames';
+import * as scrolls from '../content/scrolls';
+import * as histories from '../content/histories';
import actions from '../actions';
+import Follow from '../content/follow';
+import operations from '../operations';
import contentReducer from '../reducers/content';
consoleFrames.initialize(window.document);
@@ -22,11 +26,37 @@ window.addEventListener("keypress", (e) => {
});
});
+const execOperation = (operation) => {
+ switch (operation.type) {
+ case operations.SCROLL_LINES:
+ return scrolls.scrollLines(window, operation.count);
+ case operations.SCROLL_PAGES:
+ return scrolls.scrollPages(window, operation.count);
+ case operations.SCROLL_TOP:
+ return scrolls.scrollTop(window);
+ case operations.SCROLL_BOTTOM:
+ return scrolls.scrollBottom(window);
+ case operations.SCROLL_LEFT:
+ return scrolls.scrollLeft(window);
+ case operations.SCROLL_RIGHT:
+ return scrolls.scrollRight(window);
+ case operations.FOLLOW_START:
+ return new Follow(window.document, operation.newTab);
+ case operations.HISTORY_PREV:
+ return histories.prev(window);
+ case operations.HISTORY_NEXT:
+ return histories.next(window);
+ }
+}
+
browser.runtime.onMessage.addListener((action) => {
switch (action.type) {
case actions.CONSOLE_HIDE:
window.focus();
return consoleFrames.blur(window.document);
+ case 'require.content.operation':
+ execOperation(action.operation);
+ return Promise.resolve();
case 'vimvixen.command.enter':
return browser.runtime.sendMessage({
type: 'event.cmd.enter',
diff --git a/src/operations/index.js b/src/operations/index.js
index 16c05f2..6c2f05a 100644
--- a/src/operations/index.js
+++ b/src/operations/index.js
@@ -1,4 +1,15 @@
export default {
+ 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',
+
+ // background
TABS_CLOSE: 'tabs.close',
TABS_REOPEN: 'tabs.reopen',
TABS_PREV: 'tabs.prev',
diff --git a/src/reducers/background.js b/src/reducers/background.js
index 1bba13b..7a279c9 100644
--- a/src/reducers/background.js
+++ b/src/reducers/background.js
@@ -1,5 +1,4 @@
import * as tabs from '../background/tabs';
-import * as zooms from '../background/zooms';
import * as consoleActions from '../actions/console';
import actions from '../actions';
diff --git a/src/reducers/content.js b/src/reducers/content.js
index bcf1160..ce59b18 100644
--- a/src/reducers/content.js
+++ b/src/reducers/content.js
@@ -1,7 +1,4 @@
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 = {}) {
@@ -17,32 +14,5 @@ export default function reducer(state, action = {}) {
}
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;
}
}