diff --git a/README.md b/README.md index fadb9c5..8e4f596 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Please create an [issue](https://github.com/vn-input/chrome-unikey/issues) for a ``` source /path/to/emsdk/emsdk_env.sh cd chrome-unikey + git submodule init + git submodule update make ``` diff --git a/main.js b/main.js index 2297ca3..4a38098 100644 --- a/main.js +++ b/main.js @@ -96,6 +96,14 @@ var update_composition = function() { }); } +var commit_and_reset = function() { + ime_api.commitText({ + "contextID": context_id, + "text": unikey.get_result(), + }); + unikey.reset(); +} + ime_api.onKeyEvent.addListener(function(engineID, keyData) { if (keyData.type != "keydown") { if (keyData.key == "Shift") { @@ -120,34 +128,22 @@ ime_api.onKeyEvent.addListener(function(engineID, keyData) { return true; } - if (!keyData.ctrlKey && keyData.key.match(INPUT_METHOD_KEYS)) { + if (!keyData.ctrlKey && !keyData.altKey && keyData.key.length == 1 && keyData.key.charCodeAt(0) > 0) { unikey.process_char(keyData.key.charCodeAt(0)); - update_composition(); + if (keyData.key.match(INPUT_METHOD_KEYS)) { + update_composition(); + } else { + commit_and_reset(); + } return true; } - if (keyData.code.match(/(AudioVolume|Brightness)/)) { - return false; + if ((keyData.ctrlKey && keyData.key != "Ctrl") + || (keyData.altKey && keyData.key != "Alt") + || keyData.code.match(/^(Arrow|Tab)/)) { + commit_and_reset(); } - if (keyData.key == ' ' && unikey_opts[KEY_AUTORESTORE]) { - unikey.process_char(keyData.key.charCodeAt(0)); - ime_api.commitText({ - "contextID": context_id, - "text": unikey.get_result(), - }); - unikey.reset(); - return true; - } - - // console.log(keyData); - - ime_api.commitText({ - "contextID": context_id, - "text": unikey.get_result(), - }); - unikey.reset(); - return false; }); diff --git a/template/manifest.json b/template/manifest.json index f241464..5b4f92e 100644 --- a/template/manifest.json +++ b/template/manifest.json @@ -1,6 +1,6 @@ { "name": "__MSG_appName__", - "version": "0.4.1", + "version": "0.5.0", "manifest_version": 2, "description": "__MSG_appDesc__", "short_name": "Unikey",