aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-13 12:00:39 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-13 12:00:39 +0900
commit082450928a35ea8d35fdbcd176dbd972e45acfec (patch)
tree5973294649d322b1dc6edd2bbb07658aa499fab3 /src/content/index.js
parente7342e9c237e1deea69ed66e07b7f79cd534056e (diff)
use key-queue for input
Diffstat (limited to 'src/content/index.js')
-rw-r--r--src/content/index.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/content/index.js b/src/content/index.js
index 514f964..e882a68 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,28 +1,33 @@
import * as scrolls from './scrolls';
-const invokeEvent = (type) => {
- switch (type) {
+const invokeEvent = (action) => {
+ if (typeof action === 'undefined' || action === null) {
+ return;
+ }
+
+ switch (action[0]) {
case 'scroll.up':
- scrolls.scrollUp(window);
+ scrolls.scrollUp(window, action[1] || 1);
break;
case 'scroll.down':
- scrolls.scrollDown(window);
+ scrolls.scrollDown(window, action[1] || 1);
break;
}
}
window.addEventListener("keydown", (e) => {
- browser.runtime.sendMessage({
+ let request = {
+ type: 'event.keydown',
code: e.keyCode,
shift: e.shift,
alt: e.alt,
meta: e.meta,
ctrl: e.ctrl,
- }).then((response) => {
- if (response) {
- invokeEvent(response);
- }
- }, (err) => {
- console.log(`Vim Vixen: ${err}`);
- });
+ }
+
+ browser.runtime.sendMessage(request)
+ .then(invokeEvent,
+ (err) => {
+ console.log(`Vim Vixen: ${err}`);
+ });
});