From 359fdb528821844f3c2fda718b82ce229a64b29f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 10 Sep 2017 15:49:51 +0900 Subject: blur as action/reducer --- src/console/console.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/console/console.js') diff --git a/src/console/console.js b/src/console/console.js index d79e154..f83f79c 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -1,5 +1,6 @@ import './console.scss'; import * as backgroundActions from '../actions/background'; +import * as consoleActions from '../actions/console'; import Completion from './completion'; import consoleReducer from '../reducers/console'; @@ -9,12 +10,6 @@ var completion = null; var completionOrigin = ""; let state = consoleReducer(undefined, {}); -const blurMessage = () => { - return { - type: 'vimvixen.command.blur' - }; -}; - const keydownMessage = (input) => { return { type: 'vimvixen.command.enter', @@ -23,7 +18,7 @@ const keydownMessage = (input) => { }; const handleBlur = () => { - return browser.runtime.sendMessage(blurMessage()); + return browser.runtime.sendMessage(consoleActions.hide()); }; const completeNext = () => { @@ -57,9 +52,11 @@ const completePrev = () => { } const handleKeydown = (e) => { + let input = window.document.querySelector('#vimvixen-console-command-input'); + switch(e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: - return browser.runtime.sendMessage(blurMessage()); + return input.blur(); case KeyboardEvent.DOM_VK_RETURN: return browser.runtime.sendMessage(keydownMessage(e.target)); case KeyboardEvent.DOM_VK_TAB: @@ -183,3 +180,7 @@ browser.runtime.onMessage.addListener((action) => { state = nextState; } }); + +window.addEventListener('load', () => { + update({}, state); +}); -- cgit v1.2.3