remove follow on activated

jh-changes
Shin'ya Ueoka 7 years ago
parent a052ec92b7
commit 685164629d
  1. 21
      src/content/follow.js

@ -35,7 +35,8 @@ export default class Follow {
return; return;
} else if (keyCode === KeyboardEvent.DOM_VK_ENTER || } else if (keyCode === KeyboardEvent.DOM_VK_ENTER ||
keyCode === KeyboardEvent.DOM_VK_RETURN) { keyCode === KeyboardEvent.DOM_VK_RETURN) {
this.openUrl(this.keys); let chars = Follow.codeChars(this.keys);
this.hintElements[chars].activate();
return; return;
} else if (Follow.availableKey(keyCode)) { } else if (Follow.availableKey(keyCode)) {
this.keys.push(keyCode); this.keys.push(keyCode);
@ -44,20 +45,23 @@ export default class Follow {
this.keys.pop(); this.keys.pop();
} }
this.refreshKeys();
}
let keysAsString = Follow.codeChars(this.keys); refreshKeys() {
let chars = Follow.codeChars(this.keys);
let shown = Object.keys(this.hintElements).filter((key) => { let shown = Object.keys(this.hintElements).filter((key) => {
return key.startsWith(keysAsString); return key.startsWith(chars);
}); });
let hidden = Object.keys(this.hintElements).filter((key) => { let hidden = Object.keys(this.hintElements).filter((key) => {
return !key.startsWith(keysAsString); return !key.startsWith(chars);
}); });
if (shown.length == 0) { if (shown.length == 0) {
this.remove(); this.remove();
return; return;
} else if (shown.length == 1) { } else if (shown.length == 1) {
this.openUrl(this.keys); this.remove();
return; this.hintElements[chars].activate();
} }
shown.forEach((key) => { shown.forEach((key) => {
@ -76,11 +80,6 @@ export default class Follow {
}); });
} }
openUrl(keys) {
let chars = Follow.codeChars(keys);
this.hintElements[chars].activate();
}
static availableKey(keyCode) { static availableKey(keyCode) {
return ( return (
KeyboardEvent.DOM_VK_0 <= keyCode && keyCode <= KeyboardEvent.DOM_VK_9 || KeyboardEvent.DOM_VK_0 <= keyCode && keyCode <= KeyboardEvent.DOM_VK_9 ||