aboutsummaryrefslogtreecommitdiff
path: root/src/background/key-queue.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-13 17:30:18 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-13 17:30:18 +0900
commite45985088e0bbd041a567bab6b7665d2906528e4 (patch)
tree5e99b3f10e6b553b0f3b0d5afa811b6133bb9798 /src/background/key-queue.js
parentd169661e030e53b6a1635f86205f9fc42d2b7ef2 (diff)
parent41069cf527ed159d6c5ff89cc77867537025c9f5 (diff)
Merge branch 'basic-features'
Diffstat (limited to 'src/background/key-queue.js')
-rw-r--r--src/background/key-queue.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/background/key-queue.js b/src/background/key-queue.js
new file mode 100644
index 0000000..e21399e
--- /dev/null
+++ b/src/background/key-queue.js
@@ -0,0 +1,38 @@
+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_G }, { code: KeyboardEvent.DOM_VK_G }], action: [ actions.SCROLL_TOP ]},
+ { keys: [{ code: KeyboardEvent.DOM_VK_G, shift: true }], action: [ actions.SCROLL_BOTTOM ]},
+ { 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);
+ let filtered = DEFAULT_KEYMAP.filter((map) => {
+ return keys.hasPrefix(map.keys, this.data)
+ });
+
+ if (filtered.length == 0) {
+ this.data = [];
+ return;
+ } else if (filtered.length == 1) {
+ let map = filtered[0];
+ if (map.keys.length == this.data.length) {
+ this.data = [];
+ return map.action;
+ }
+ }
+ return null;
+ }
+}