use key-queue for input
This commit is contained in:
parent
e7342e9c23
commit
082450928a
7 changed files with 134 additions and 40 deletions
28
src/background/key-queue.js
Normal file
28
src/background/key-queue.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import * as keys from './keys';
|
||||
import * as actions from '../shared/actions';
|
||||
|
||||
const DEFAULT_KEYMAP = [
|
||||
{ keys: [{ code: KeyboardEvent.DOM_VK_K }], action: [ actions.SCROLL_UP, 1 ]},
|
||||
{ keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_DOWN, 1 ]},
|
||||
{ keys: [{ code: KeyboardEvent.DOM_VK_H }], action: [ actions.TABS_PREV, 1 ]},
|
||||
{ keys: [{ code: KeyboardEvent.DOM_VK_L }], action: [ actions.TABS_NEXT, 1 ]},
|
||||
]
|
||||
|
||||
export default class KeyQueue {
|
||||
|
||||
constructor(keymap) {
|
||||
this.data = [];
|
||||
this.keymap = keymap;
|
||||
}
|
||||
|
||||
push(key) {
|
||||
this.data.push(key);
|
||||
for (let map of DEFAULT_KEYMAP) {
|
||||
if (keys.keysEquals(map.keys, this.data)) {
|
||||
this.data = [];
|
||||
return map.action
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in a new issue