remove deprecated property in KeyboardEvent
This commit is contained in:
parent
eff8d9a83e
commit
5ac1f60ece
10 changed files with 32 additions and 87 deletions
|
@ -1,10 +1,16 @@
|
|||
import actions from '../actions';
|
||||
|
||||
const keyPress = (code, ctrl) => {
|
||||
const asKeymapChars = (key, ctrl) => {
|
||||
if (ctrl) {
|
||||
return '<C-' + key.toUpperCase() + '>';
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
const keyPress = (key, ctrl) => {
|
||||
return {
|
||||
type: actions.INPUT_KEY_PRESS,
|
||||
code,
|
||||
ctrl
|
||||
key: asKeymapChars(key, ctrl),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import * as inputActions from '../actions/input';
|
||||
import * as keys from '../shared/keys';
|
||||
import * as operationActions from '../actions/operation';
|
||||
|
||||
export default class BackgroundInputComponent {
|
||||
|
@ -37,15 +36,14 @@ export default class BackgroundInputComponent {
|
|||
}
|
||||
|
||||
handleKeysChanged(sender, input) {
|
||||
let prefix = keys.asKeymapChars(input.keys);
|
||||
let matched = Object.keys(this.keymaps).filter((keyStr) => {
|
||||
return keyStr.startsWith(prefix);
|
||||
return keyStr.startsWith(input.keys);
|
||||
});
|
||||
if (matched.length === 0) {
|
||||
this.store.dispatch(inputActions.clearKeys(), sender);
|
||||
return Promise.resolve();
|
||||
} else if (matched.length > 1 ||
|
||||
matched.length === 1 && prefix !== matched[0]) {
|
||||
matched.length === 1 && input.keys !== matched[0]) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
let operation = this.keymaps[matched];
|
||||
|
|
|
@ -35,7 +35,7 @@ export default class BackgroundComponent {
|
|||
switch (message.type) {
|
||||
case messages.KEYDOWN:
|
||||
return this.store.dispatch(
|
||||
inputActions.keyPress(message.code, message.ctrl), sender);
|
||||
inputActions.keyPress(message.key, message.ctrl), sender);
|
||||
case messages.OPEN_URL:
|
||||
if (message.newTab) {
|
||||
return this.store.dispatch(
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class ContentInputComponent {
|
|||
}
|
||||
browser.runtime.sendMessage({
|
||||
type: messages.KEYDOWN,
|
||||
code: e.which,
|
||||
key: e.key,
|
||||
ctrl: e.ctrlKey
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ followStore.subscribe(() => {
|
|||
console.error(e);
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const contentInputComponent = new ContentInputComponent(window);
|
||||
|
||||
consoleFrames.initialize(window.document);
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
import actions from '../actions';
|
||||
|
||||
const defaultState = {
|
||||
keys: [],
|
||||
keys: '',
|
||||
};
|
||||
|
||||
export default function reducer(state = defaultState, action = {}) {
|
||||
switch (action.type) {
|
||||
case actions.INPUT_KEY_PRESS:
|
||||
return Object.assign({}, state, {
|
||||
keys: state.keys.concat([
|
||||
{
|
||||
code: action.code,
|
||||
ctrl: action.ctrl
|
||||
}
|
||||
])
|
||||
keys: state.keys + action.key
|
||||
});
|
||||
case actions.INPUT_CLEAR_KEYS:
|
||||
return Object.assign({}, state, {
|
||||
keys: [],
|
||||
keys: '',
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
const asKeymapChars = (keys) => {
|
||||
return keys.map((k) => {
|
||||
let c = String.fromCharCode(k.code);
|
||||
if (k.ctrl) {
|
||||
return '<C-' + c.toUpperCase() + '>';
|
||||
}
|
||||
return c;
|
||||
}).join('');
|
||||
};
|
||||
|
||||
const asCaretChars = (keys) => {
|
||||
return keys.map((k) => {
|
||||
let c = String.fromCharCode(k.code);
|
||||
if (k.ctrl) {
|
||||
return '^' + c.toUpperCase();
|
||||
}
|
||||
return c;
|
||||
}).join('');
|
||||
};
|
||||
|
||||
export { asKeymapChars, asCaretChars };
|
Reference in a new issue