diff options
Diffstat (limited to 'src/console/components')
-rw-r--r-- | src/console/components/console.js | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/console/components/console.js b/src/console/components/console.js index 605feb2..e83a1c9 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -25,23 +25,18 @@ export default class ConsoleComponent { } onBlur() { - return browser.runtime.sendMessage({ - type: messages.CONSOLE_BLURRED, - }); + let state = this.store.getState(); + if (state.mode === 'command') { + this.hideCommand(); + } } onKeyDown(e) { - let doc = this.wrapper.ownerDocument; - let input = doc.querySelector('#vimvixen-console-command-input'); - switch (e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: - return input.blur(); + return this.hideCommand(); case KeyboardEvent.DOM_VK_RETURN: - return browser.runtime.sendMessage({ - type: messages.CONSOLE_ENTERED, - text: e.target.value - }).then(this.onBlur); + return this.onEntered(e.target.value); case KeyboardEvent.DOM_VK_TAB: if (e.shiftKey) { this.store.dispatch(consoleActions.completionPrev()); @@ -54,6 +49,22 @@ export default class ConsoleComponent { } } + onEntered(value) { + let state = this.store.getState(); + if (state.mode === 'command') { + browser.runtime.sendMessage({ + type: messages.CONSOLE_ENTER_COMMAND, + text: value, + }).then(this.hideCommand); + } else if (state.mode === 'find') { + this.hideCommand(); + window.top.postMessage(JSON.stringify({ + type: messages.CONSOLE_ENTER_FIND, + text: value, + }), '*'); + } + } + onInput(e) { this.store.dispatch(consoleActions.setConsoleText(e.target.value)); @@ -78,6 +89,13 @@ export default class ConsoleComponent { } } + hideCommand() { + this.store.dispatch(consoleActions.hideCommand()); + window.top.postMessage(JSON.stringify({ + type: messages.CONSOLE_UNFOCUS, + }), '*'); + } + update() { let state = this.store.getState(); |