From e2aae9cff249db0617f082a34a8a3a4f5dd1f4f1 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 09:56:54 +0900 Subject: [PATCH] follow from content-input --- src/components/content-input.js | 3 +++ src/components/follow.js | 12 +++--------- src/content/index.js | 3 +++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/content-input.js b/src/components/content-input.js index 0f15937..9568caf 100644 --- a/src/components/content-input.js +++ b/src/components/content-input.js @@ -49,6 +49,9 @@ export default class ContentInputComponent { let stop = false; for (let listener of this.onKeyListeners) { stop = stop || listener(e.key, e.ctrlKey); + if (stop) { + break; + } } if (stop) { e.preventDefault(); diff --git a/src/components/follow.js b/src/components/follow.js index 365bb20..25db0c4 100644 --- a/src/components/follow.js +++ b/src/components/follow.js @@ -22,9 +22,6 @@ export default class FollowComponent { this.store = store; this.hintElements = {}; this.state = {}; - - let doc = wrapper.ownerDocument; - doc.addEventListener('keydown', this.onKeyDown.bind(this)); } update() { @@ -39,12 +36,11 @@ export default class FollowComponent { } } - onKeyDown(e) { + key(key) { if (!this.state.enabled) { - return; + return false; } - let { key } = e; switch (key) { case 'Enter': this.activate(this.hintElements[this.state.keys].target); @@ -62,9 +58,7 @@ export default class FollowComponent { } break; } - - e.stopPropagation(); - e.preventDefault(); + return true; } updateHints() { diff --git a/src/content/index.js b/src/content/index.js index ad891ca..d380291 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -13,6 +13,9 @@ const followComponent = new FollowComponent(window.document.body, store); const contentInputComponent = new ContentInputComponent(window.document.body, store); const keymapperComponent = new KeymapperComponent(store); +contentInputComponent.onKey((key, ctrl) => { + return followComponent.key(key, ctrl); +}); contentInputComponent.onKey((key, ctrl) => { return keymapperComponent.key(key, ctrl); });