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';
|
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 {
|
return {
|
||||||
type: actions.INPUT_KEY_PRESS,
|
type: actions.INPUT_KEY_PRESS,
|
||||||
code,
|
key: asKeymapChars(key, ctrl),
|
||||||
ctrl
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as inputActions from '../actions/input';
|
import * as inputActions from '../actions/input';
|
||||||
import * as keys from '../shared/keys';
|
|
||||||
import * as operationActions from '../actions/operation';
|
import * as operationActions from '../actions/operation';
|
||||||
|
|
||||||
export default class BackgroundInputComponent {
|
export default class BackgroundInputComponent {
|
||||||
|
@ -37,15 +36,14 @@ export default class BackgroundInputComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeysChanged(sender, input) {
|
handleKeysChanged(sender, input) {
|
||||||
let prefix = keys.asKeymapChars(input.keys);
|
|
||||||
let matched = Object.keys(this.keymaps).filter((keyStr) => {
|
let matched = Object.keys(this.keymaps).filter((keyStr) => {
|
||||||
return keyStr.startsWith(prefix);
|
return keyStr.startsWith(input.keys);
|
||||||
});
|
});
|
||||||
if (matched.length === 0) {
|
if (matched.length === 0) {
|
||||||
this.store.dispatch(inputActions.clearKeys(), sender);
|
this.store.dispatch(inputActions.clearKeys(), sender);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else if (matched.length > 1 ||
|
} else if (matched.length > 1 ||
|
||||||
matched.length === 1 && prefix !== matched[0]) {
|
matched.length === 1 && input.keys !== matched[0]) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
let operation = this.keymaps[matched];
|
let operation = this.keymaps[matched];
|
||||||
|
|
|
@ -35,7 +35,7 @@ export default class BackgroundComponent {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case messages.KEYDOWN:
|
case messages.KEYDOWN:
|
||||||
return this.store.dispatch(
|
return this.store.dispatch(
|
||||||
inputActions.keyPress(message.code, message.ctrl), sender);
|
inputActions.keyPress(message.key, message.ctrl), sender);
|
||||||
case messages.OPEN_URL:
|
case messages.OPEN_URL:
|
||||||
if (message.newTab) {
|
if (message.newTab) {
|
||||||
return this.store.dispatch(
|
return this.store.dispatch(
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default class ContentInputComponent {
|
||||||
}
|
}
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
type: messages.KEYDOWN,
|
type: messages.KEYDOWN,
|
||||||
code: e.which,
|
key: e.key,
|
||||||
ctrl: e.ctrlKey
|
ctrl: e.ctrlKey
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ followStore.subscribe(() => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
const contentInputComponent = new ContentInputComponent(window);
|
const contentInputComponent = new ContentInputComponent(window);
|
||||||
|
|
||||||
consoleFrames.initialize(window.document);
|
consoleFrames.initialize(window.document);
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
import actions from '../actions';
|
import actions from '../actions';
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
keys: [],
|
keys: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action = {}) {
|
export default function reducer(state = defaultState, action = {}) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actions.INPUT_KEY_PRESS:
|
case actions.INPUT_KEY_PRESS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
keys: state.keys.concat([
|
keys: state.keys + action.key
|
||||||
{
|
|
||||||
code: action.code,
|
|
||||||
ctrl: action.ctrl
|
|
||||||
}
|
|
||||||
])
|
|
||||||
});
|
});
|
||||||
case actions.INPUT_CLEAR_KEYS:
|
case actions.INPUT_CLEAR_KEYS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
keys: [],
|
keys: '',
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
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 };
|
|
|
@ -5,10 +5,15 @@ import * as inputActions from '../../src/actions/input';
|
||||||
describe("input actions", () => {
|
describe("input actions", () => {
|
||||||
describe("keyPress", () => {
|
describe("keyPress", () => {
|
||||||
it('create INPUT_KEY_PRESS action', () => {
|
it('create INPUT_KEY_PRESS action', () => {
|
||||||
let action = inputActions.keyPress(123, true);
|
let action = inputActions.keyPress('a', false);
|
||||||
expect(action.type).to.equal(actions.INPUT_KEY_PRESS);
|
expect(action.type).to.equal(actions.INPUT_KEY_PRESS);
|
||||||
expect(action.code).to.equal(123);
|
expect(action.key).to.equal('a');
|
||||||
expect(action.ctrl).to.be.true;
|
});
|
||||||
|
|
||||||
|
it('create INPUT_KEY_PRESS action from key with ctrl', () => {
|
||||||
|
let action = inputActions.keyPress('b', true);
|
||||||
|
expect(action.type).to.equal(actions.INPUT_KEY_PRESS);
|
||||||
|
expect(action.key).to.equal('<C-B>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,30 +5,22 @@ import inputReducer from '../../src/reducers/input';
|
||||||
describe("input reducer", () => {
|
describe("input reducer", () => {
|
||||||
it('return the initial state', () => {
|
it('return the initial state', () => {
|
||||||
let state = inputReducer(undefined, {});
|
let state = inputReducer(undefined, {});
|
||||||
expect(state).to.have.deep.property('keys', []);
|
expect(state).to.have.deep.property('keys', '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return next state for INPUT_KEY_PRESS', () => {
|
it('return next state for INPUT_KEY_PRESS', () => {
|
||||||
let action = { type: actions.INPUT_KEY_PRESS, code: 123, ctrl: true };
|
let action = { type: actions.INPUT_KEY_PRESS, key: 'a' };
|
||||||
let state = inputReducer(undefined, action);
|
let state = inputReducer(undefined, action);
|
||||||
expect(state).to.have.deep.property('keys', [{ code: 123, ctrl: true }]);
|
expect(state).to.have.deep.property('keys', 'a');
|
||||||
|
|
||||||
action = { type: actions.INPUT_KEY_PRESS, code: 456, ctrl: false };
|
action = { type: actions.INPUT_KEY_PRESS, key: '<C-B>' };
|
||||||
state = inputReducer(state, action);
|
state = inputReducer(state, action);
|
||||||
expect(state).to.have.deep.property('keys', [
|
expect(state).to.have.deep.property('keys', 'a<C-B>');
|
||||||
{ code: 123, ctrl: true },
|
|
||||||
{ code: 456, ctrl: false }
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return next state for INPUT_CLEAR_KEYS', () => {
|
it('return next state for INPUT_CLEAR_KEYS', () => {
|
||||||
let action = { type: actions.INPUT_CLEAR_KEYS };
|
let action = { type: actions.INPUT_CLEAR_KEYS };
|
||||||
let state = inputReducer({
|
let state = inputReducer({ keys: 'abc' }, action);
|
||||||
keys: [
|
expect(state).to.have.deep.property('keys', '');
|
||||||
{ code: 123, ctrl: true },
|
|
||||||
{ code: 456, ctrl: false }
|
|
||||||
]
|
|
||||||
}, action);
|
|
||||||
expect(state).to.have.deep.property('keys', []);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { expect } from "chai";
|
|
||||||
import * as keys from '../../src/shared/keys';
|
|
||||||
|
|
||||||
describe("keys", () => {
|
|
||||||
const KEYMAP = {
|
|
||||||
'g<C-X>GG': [],
|
|
||||||
'gg': { type: 'scroll.top' },
|
|
||||||
};
|
|
||||||
|
|
||||||
const g = 'g'.charCodeAt(0);
|
|
||||||
const G = 'G'.charCodeAt(0);
|
|
||||||
const x = 'x'.charCodeAt(0);
|
|
||||||
|
|
||||||
describe('#asKeymapChars', () => {
|
|
||||||
let keySequence = [
|
|
||||||
{ code: g },
|
|
||||||
{ code: x, ctrl: true },
|
|
||||||
{ code: G }
|
|
||||||
];
|
|
||||||
expect(keys.asKeymapChars(keySequence)).to.equal('g<C-X>G');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#asCaretChars', () => {
|
|
||||||
let keySequence = [
|
|
||||||
{ code: g },
|
|
||||||
{ code: x, ctrl: true },
|
|
||||||
{ code: G }
|
|
||||||
];
|
|
||||||
expect(keys.asCaretChars(keySequence)).to.equal('g^XG');
|
|
||||||
});
|
|
||||||
});
|
|
Reference in a new issue