enable/disable addon by keys

jh-changes
Shin'ya Ueoka 7 years ago
parent 59f7ef205d
commit dc6d93c1da
  1. 7
      src/content/actions/operation.js
  2. 12
      src/content/components/common/keymapper.js
  3. 3
      src/content/reducers/index.js
  4. 5
      src/shared/operations.js

@ -4,9 +4,16 @@ import * as scrolls from 'content/scrolls';
import * as navigates from 'content/navigates'; import * as navigates from 'content/navigates';
import * as urls from 'content/urls'; import * as urls from 'content/urls';
import * as consoleFrames from 'content/console-frames'; import * as consoleFrames from 'content/console-frames';
import * as addonActions from './addon';
const exec = (operation) => { const exec = (operation) => {
switch (operation.type) { switch (operation.type) {
case operations.ADDON_ENABLE:
return addonActions.enable();
case operations.ADDON_DISABLE:
return addonActions.disable();
case operations.ADDON_TOGGLE_ENABLED:
return addonActions.toggleEnabled();
case operations.SCROLL_VERTICALLY: case operations.SCROLL_VERTICALLY:
return scrolls.scrollVertically(window, operation.count); return scrolls.scrollVertically(window, operation.count);
case operations.SCROLL_HORIZONALLY: case operations.SCROLL_HORIZONALLY:

@ -1,5 +1,6 @@
import * as inputActions from 'content/actions/input'; import * as inputActions from 'content/actions/input';
import * as operationActions from 'content/actions/operation'; import * as operationActions from 'content/actions/operation';
import operations from 'shared/operations';
export default class KeymapperComponent { export default class KeymapperComponent {
constructor(store) { constructor(store) {
@ -10,12 +11,23 @@ export default class KeymapperComponent {
} }
key(key) { key(key) {
let enabled = this.store.getState().addon.enabled;
this.store.dispatch(inputActions.keyPress(key)); this.store.dispatch(inputActions.keyPress(key));
let input = this.store.getState().input; let input = this.store.getState().input;
let matched = Object.keys(input.keymaps).filter((keyStr) => { let matched = Object.keys(input.keymaps).filter((keyStr) => {
return keyStr.startsWith(input.keys); return keyStr.startsWith(input.keys);
}); });
if (!enabled) {
// available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if
// the addon disabled
matched = matched.filter((keys) => {
let type = input.keymaps[keys].type;
return type === operations.ADDON_ENABLE ||
type === operations.ADDON_TOGGLE_ENABLED;
});
}
if (matched.length === 0) { if (matched.length === 0) {
this.store.dispatch(inputActions.clearKeys()); this.store.dispatch(inputActions.clearKeys());
return false; return false;

@ -1,14 +1,17 @@
import addonReducer from './addon';
import inputReducer from './input'; import inputReducer from './input';
import followReducer from './follow'; import followReducer from './follow';
// Make setting reducer instead of re-use // Make setting reducer instead of re-use
const defaultState = { const defaultState = {
addon: addonReducer(undefined, {}),
input: inputReducer(undefined, {}), input: inputReducer(undefined, {}),
follow: followReducer(undefined, {}), follow: followReducer(undefined, {}),
}; };
export default function reducer(state = defaultState, action = {}) { export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, { return Object.assign({}, state, {
addon: addonReducer(state.addon, action),
input: inputReducer(state.input, action), input: inputReducer(state.input, action),
follow: followReducer(state.follow, action), follow: followReducer(state.follow, action),
}); });

@ -1,4 +1,9 @@
export default { export default {
// Addons
ADDON_ENABLE: 'addon.enable',
ADDON_DISABLE: 'addon.disable',
ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled',
// Command // Command
COMMAND_SHOW: 'command.show', COMMAND_SHOW: 'command.show',
COMMAND_SHOW_OPEN: 'command.show.open', COMMAND_SHOW_OPEN: 'command.show.open',