Merge pull request #126 from ueokande/69-fix-completion-navigate

fix completion navigate
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit e4ff3a78fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/console/components/console.js

@ -4,7 +4,6 @@ import * as consoleActions from 'console/actions/console';
export default class ConsoleComponent { export default class ConsoleComponent {
constructor(wrapper, store) { constructor(wrapper, store) {
this.wrapper = wrapper; this.wrapper = wrapper;
this.prevValue = '';
this.prevState = {}; this.prevState = {};
this.completionOrigin = ''; this.completionOrigin = '';
this.store = store; this.store = store;
@ -13,7 +12,7 @@ export default class ConsoleComponent {
let input = doc.querySelector('#vimvixen-console-command-input'); let input = doc.querySelector('#vimvixen-console-command-input');
input.addEventListener('blur', this.onBlur.bind(this)); input.addEventListener('blur', this.onBlur.bind(this));
input.addEventListener('keydown', this.onKeyDown.bind(this)); input.addEventListener('keydown', this.onKeyDown.bind(this));
input.addEventListener('keyup', this.onKeyUp.bind(this)); input.addEventListener('input', this.onInput.bind(this));
this.hideCommand(); this.hideCommand();
this.hideMessage(); this.hideMessage();
@ -53,22 +52,14 @@ export default class ConsoleComponent {
} }
} }
onKeyUp(e) { onInput(e) {
if (e.keyCode === KeyboardEvent.DOM_VK_TAB) {
return;
}
if (e.target.value === this.prevValue) {
return;
}
let doc = this.wrapper.ownerDocument; let doc = this.wrapper.ownerDocument;
let input = doc.querySelector('#vimvixen-console-command-input'); let input = doc.querySelector('#vimvixen-console-command-input');
this.completionOrigin = input.value; this.completionOrigin = input.value;
this.prevValue = e.target.value;
return browser.runtime.sendMessage({ return browser.runtime.sendMessage({
type: messages.CONSOLE_QUERY_COMPLETIONS, type: messages.CONSOLE_QUERY_COMPLETIONS,
text: e.target.value text: e.target.value,
}).then((completions) => { }).then((completions) => {
this.store.dispatch(consoleActions.setCompletions(completions)); this.store.dispatch(consoleActions.setCompletions(completions));
}); });
@ -113,7 +104,7 @@ export default class ConsoleComponent {
input.focus(); input.focus();
window.focus(); window.focus();
this.prevValue = ''; this.onInput({ target: input });
} }
hideCommand() { hideCommand() {