save keymap in input store in content
This commit is contained in:
parent
892eb8a6a6
commit
355c0c6457
6 changed files with 19 additions and 24 deletions
|
@ -2,16 +2,13 @@ export default {
|
|||
// User input
|
||||
INPUT_KEY_PRESS: 'input.key,press',
|
||||
INPUT_CLEAR_KEYS: 'input.clear.keys',
|
||||
INPUT_SET_KEYMAPS: 'input.set,keymaps',
|
||||
INPUT_SET_KEYMAPS: 'input.set.keymaps',
|
||||
|
||||
// Completion
|
||||
COMPLETION_SET_ITEMS: 'completion.set.items',
|
||||
COMPLETION_SELECT_NEXT: 'completions.select.next',
|
||||
COMPLETION_SELECT_PREV: 'completions.select.prev',
|
||||
|
||||
// Settings
|
||||
SETTING_SET_SETTINGS: 'setting.set.settings',
|
||||
|
||||
// Follow
|
||||
FOLLOW_ENABLE: 'follow.enable',
|
||||
FOLLOW_DISABLE: 'follow.disable',
|
||||
|
|
|
@ -20,4 +20,11 @@ const clearKeys = () => {
|
|||
};
|
||||
};
|
||||
|
||||
export { keyPress, clearKeys };
|
||||
const setKeymaps = (keymaps) => {
|
||||
return {
|
||||
type: actions.INPUT_SET_KEYMAPS,
|
||||
keymaps,
|
||||
};
|
||||
};
|
||||
|
||||
export { keyPress, clearKeys, setKeymaps };
|
||||
|
|
|
@ -10,14 +10,10 @@ export default class KeymapperComponent {
|
|||
}
|
||||
|
||||
key(key, ctrl) {
|
||||
let keymaps = this.keymaps();
|
||||
if (!keymaps) {
|
||||
return;
|
||||
}
|
||||
this.store.dispatch(inputActions.keyPress(key, ctrl));
|
||||
|
||||
let input = this.store.getState().input;
|
||||
let matched = Object.keys(keymaps).filter((keyStr) => {
|
||||
let matched = Object.keys(input.keymaps).filter((keyStr) => {
|
||||
return keyStr.startsWith(input.keys);
|
||||
});
|
||||
if (matched.length === 0) {
|
||||
|
@ -27,17 +23,9 @@ export default class KeymapperComponent {
|
|||
matched.length === 1 && input.keys !== matched[0]) {
|
||||
return true;
|
||||
}
|
||||
let operation = keymaps[matched];
|
||||
let operation = input.keymaps[matched];
|
||||
this.store.dispatch(operationActions.exec(operation));
|
||||
this.store.dispatch(inputActions.clearKeys());
|
||||
return true;
|
||||
}
|
||||
|
||||
keymaps() {
|
||||
let settings = this.store.getState().setting.settings;
|
||||
if (!settings || !settings.json) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parse(settings.json).keymaps;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import './console-frame.scss';
|
||||
import * as consoleFrames from './console-frames';
|
||||
import * as settingActions from 'settings/actions/setting';
|
||||
import * as inputActions from './actions/input';
|
||||
import { createStore } from 'shared/store';
|
||||
import ContentInputComponent from 'content/components/content-input';
|
||||
import KeymapperComponent from 'content/components/keymapper';
|
||||
|
@ -34,7 +34,8 @@ const reloadSettings = () => {
|
|||
return browser.runtime.sendMessage({
|
||||
type: messages.SETTINGS_QUERY,
|
||||
}).then((settings) => {
|
||||
store.dispatch(settingActions.set(settings));
|
||||
let keymaps = JSON.parse(settings.json).keymaps;
|
||||
store.dispatch(inputActions.setKeymaps(keymaps));
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
import settingReducer from 'settings/reducers/setting';
|
||||
import inputReducer from './input';
|
||||
import followReducer from './follow';
|
||||
|
||||
// Make setting reducer instead of re-use
|
||||
const defaultState = {
|
||||
input: inputReducer(undefined, {}),
|
||||
setting: settingReducer(undefined, {}),
|
||||
follow: followReducer(undefined, {}),
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action = {}) {
|
||||
return Object.assign({}, state, {
|
||||
input: inputReducer(state.input, action),
|
||||
setting: settingReducer(state.setting, action),
|
||||
follow: followReducer(state.follow, action),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import actions from 'content/actions';
|
|||
|
||||
const defaultState = {
|
||||
keys: '',
|
||||
keymaps: {},
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action = {}) {
|
||||
|
@ -14,6 +15,10 @@ export default function reducer(state = defaultState, action = {}) {
|
|||
return Object.assign({}, state, {
|
||||
keys: '',
|
||||
});
|
||||
case actions.INPUT_SET_KEYMAPS:
|
||||
return Object.assign({}, state, {
|
||||
keymaps: action.keymaps,
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Reference in a new issue