aboutsummaryrefslogtreecommitdiff
path: root/src/background/key-queue.js
blob: e14e995d4145d90b13b9685de4a41fcbdd462a99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
  }
}