content operations

jh-changes
Shin'ya Ueoka 7 years ago
parent b6e5153c1f
commit a61f37ad61
  1. 9
      src/actions/index.js
  2. 5
      src/actions/operation.js
  3. 2
      src/background/index.js
  4. 32
      src/background/keys.js
  5. 30
      src/content/index.js
  6. 11
      src/operations/index.js
  7. 1
      src/reducers/background.js
  8. 30
      src/reducers/content.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',

@ -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
});
}
}

@ -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);
});

@ -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) => {

@ -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',

@ -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',

@ -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';

@ -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;
}
}