use action as object

jh-changes
Shin'ya Ueoka 7 years ago
parent eff7fe276b
commit e15de17598
  1. 12
      src/background/index.js
  2. 58
      src/background/key-queue.js
  3. 14
      src/content/index.js

@ -14,9 +14,9 @@ const keyPressHandle = (request, sender) => {
return Promise.resolve(); return Promise.resolve();
} }
if (actions.isBackgroundAction(action[0])) { if (actions.isBackgroundAction(action.type)) {
return doBackgroundAction(sender, action); return doBackgroundAction(sender, action);
} else if (actions.isContentAction(action[0])) { } else if (actions.isContentAction(action.type)) {
return Promise.resolve({ return Promise.resolve({
type: 'response.action', type: 'response.action',
action: action action: action
@ -26,17 +26,17 @@ const keyPressHandle = (request, sender) => {
}; };
const doBackgroundAction = (sender, action) => { const doBackgroundAction = (sender, action) => {
switch(action[0]) { switch(action.type) {
case actions.TABS_CLOSE: case actions.TABS_CLOSE:
return tabs.closeTab(sender.tab.id); return tabs.closeTab(sender.tab.id);
case actions.TABS_REOPEN: case actions.TABS_REOPEN:
return tabs.reopenTab(); return tabs.reopenTab();
case actions.TABS_PREV: case actions.TABS_PREV:
return tabs.selectPrevTab(sender.tab.index, actions[1] || 1); return tabs.selectPrevTab(sender.tab.index, action.count);
case actions.TABS_NEXT: case actions.TABS_NEXT:
return tabs.selectNextTab(sender.tab.index, actions[1] || 1); return tabs.selectNextTab(sender.tab.index, action.count);
case actions.TABS_RELOAD: case actions.TABS_RELOAD:
return tabs.reload(sender.tab, actions[1] || false); return tabs.reload(sender.tab, actions.cache);
case actions.ZOOM_IN: case actions.ZOOM_IN:
return zooms.zoomIn(); return zooms.zoomIn();
case actions.ZOOM_OUT: case actions.ZOOM_OUT:

@ -1,35 +1,35 @@
import * as actions from '../shared/actions'; import * as actions from '../shared/actions';
const DEFAULT_KEYMAP = { const DEFAULT_KEYMAP = {
':': [ actions.CMD_OPEN ], ':': { type: actions.CMD_OPEN },
'o': [ actions.CMD_TABS_OPEN, false ], 'o': { type: actions.CMD_TABS_OPEN, alter: false },
'O': [ actions.CMD_TABS_OPEN, true ], 'O': { type: actions.CMD_TABS_OPEN, alter: true },
'b': [ actions.CMD_BUFFER ], 'b': { type: actions.CMD_BUFFER },
'k': [ actions.SCROLL_LINES, -1 ], 'k': { type: actions.SCROLL_LINES, count: -1 },
'j': [ actions.SCROLL_LINES, 1 ], 'j': { type: actions.SCROLL_LINES, count: 1 },
'<C-E>': [ actions.SCROLL_LINES, -1 ], '<C-E>': { type: actions.SCROLL_LINES, count: -1 },
'<C-Y>': [ actions.SCROLL_LINES, 1 ], '<C-Y>': { type: actions.SCROLL_LINES, count: 1 },
'<C-U>': [ actions.SCROLL_PAGES, -0.5 ], '<C-U>': { type: actions.SCROLL_PAGES, count: -0.5 },
'<C-D>': [ actions.SCROLL_PAGES, 0.5 ], '<C-D>': { type: actions.SCROLL_PAGES, count: 0.5 },
'<C-B>': [ actions.SCROLL_PAGES, -1 ], '<C-B>': { type: actions.SCROLL_PAGES, count: -1 },
'<C-F>': [ actions.SCROLL_PAGES, 1 ], '<C-F>': { type: actions.SCROLL_PAGES, count: 1 },
'gg': [ actions.SCROLL_TOP ], 'gg': { type: actions.SCROLL_TOP },
'G': [ actions.SCROLL_BOTTOM ], 'G': { type: actions.SCROLL_BOTTOM },
'0': [ actions.SCROLL_LEFT ], '0': { type: actions.SCROLL_LEFT },
'$': [ actions.SCROLL_RIGHT ], '$': { type: actions.SCROLL_RIGHT },
'd': [ actions.TABS_CLOSE ], 'd': { type: actions.TABS_CLOSE },
'u': [ actions.TABS_REOPEN], 'u': { type: actions.TABS_REOPEN },
'h': [ actions.TABS_PREV, 1 ], 'h': { type: actions.TABS_PREV, count: 1 },
'l': [ actions.TABS_NEXT, 1 ], 'l': { type: actions.TABS_NEXT, count: 1 },
'r': [ actions.TABS_RELOAD, false ], 'r': { type: actions.TABS_RELOAD, cache: false },
'R': [ actions.TABS_RELOAD, true ], 'R': { type: actions.TABS_RELOAD, cache: true },
'zi': [ actions.ZOOM_IN ], 'zi': { type: actions.ZOOM_IN },
'zo': [ actions.ZOOM_OUT ], 'zo': { type: actions.ZOOM_OUT },
'zz': [ actions.ZOOM_NEUTRAL], 'zz': { type: actions.ZOOM_NEUTRAL },
'f': [ actions.FOLLOW_START, false ], 'f': { type: actions.FOLLOW_START, newTab: false },
'F': [ actions.FOLLOW_START, true ], 'F': { type: actions.FOLLOW_START, newTab: true },
'H': [ actions.HISTORY_PREV ], 'H': { type: actions.HISTORY_PREV },
'L': [ actions.HISTORY_NEXT ], 'L': { type: actions.HISTORY_NEXT },
} }
export default class KeyQueue { export default class KeyQueue {

@ -8,16 +8,12 @@ import Follow from './follow';
let vvConsole = new ConsoleFrame(window); let vvConsole = new ConsoleFrame(window);
const doAction = (action) => { const doAction = (action) => {
if (typeof action === 'undefined' || action === null) { switch (action.type) {
return;
}
switch (action[0]) {
case actions.CMD_OPEN: case actions.CMD_OPEN:
vvConsole.showCommand(''); vvConsole.showCommand('');
break; break;
case actions.CMD_TABS_OPEN: case actions.CMD_TABS_OPEN:
if (action[1] || false) { if (action.alter) {
// alter url // alter url
vvConsole.showCommand('open ' + window.location.href); vvConsole.showCommand('open ' + window.location.href);
} else { } else {
@ -28,10 +24,10 @@ const doAction = (action) => {
vvConsole.showCommand('buffer '); vvConsole.showCommand('buffer ');
break; break;
case actions.SCROLL_LINES: case actions.SCROLL_LINES:
scrolls.scrollLines(window, action[1]); scrolls.scrollLines(window, action.count);
break; break;
case actions.SCROLL_PAGES: case actions.SCROLL_PAGES:
scrolls.scrollPages(window, action[1]); scrolls.scrollPages(window, action.count);
break; break;
case actions.SCROLL_TOP: case actions.SCROLL_TOP:
scrolls.scrollTop(window); scrolls.scrollTop(window);
@ -46,7 +42,7 @@ const doAction = (action) => {
scrolls.scrollRight(window); scrolls.scrollRight(window);
break; break;
case actions.FOLLOW_START: case actions.FOLLOW_START:
new Follow(window.document, action[1] || false); new Follow(window.document, action.newTab);
break; break;
case actions.HISTORY_PREV: case actions.HISTORY_PREV:
histories.prev(window); histories.prev(window);