Skip to content

Commit

Permalink
optimize keys handle
Browse files Browse the repository at this point in the history
  • Loading branch information
tulequ committed Mar 31, 2019
1 parent a6f557c commit 4cce8f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
40 changes: 18 additions & 22 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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;
});

Expand Down
2 changes: 1 addition & 1 deletion template/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
"version": "0.4.1",
"version": "0.5.0",
"manifest_version": 2,
"description": "__MSG_appDesc__",
"short_name": "Unikey",
Expand Down

0 comments on commit 4cce8f8

Please sign in to comment.