From 13f9b2fe1b6988f9cb3b2a06431094153cb25475 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Mon, 11 Dec 2023 10:45:03 +1100 Subject: [PATCH 1/8] Add NZ IME - add to UK extended IME --- ukextended/background.js | 52 ++++++++++++++++++++++++++++++---------- ukextended/manifest.json | 8 +++++++ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ukextended/background.js b/ukextended/background.js index 69eba67..1ed1a9f 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -15,9 +15,9 @@ limitations under the License. */ var previousCharIsMagic = false; var contextID = -1; -var lut = {"a": "à", "A": "À", "e": "è", "E": "È", "i": "ì", "I":"Ì", "o": "ò", "O":"Ò", "u":"ù", "U":"Ù", "w":"ẁ", "W":"Ẁ", "y":"ỳ", "Y":"Ỳ", "`": "`"}; +var lut = { "a": "à", "A": "À", "e": "è", "E": "È", "i": "ì", "I": "Ì", "o": "ò", "O": "Ò", "u": "ù", "U": "Ù", "w": "ẁ", "W": "Ẁ", "y": "ỳ", "Y": "Ỳ", "`": "`" }; -chrome.input.ime.onFocus.addListener(function(context) { +chrome.input.ime.onFocus.addListener(function (context) { contextID = context.contextID; }); @@ -26,25 +26,53 @@ function isPureModifier(keyData) { } chrome.input.ime.onKeyEvent.addListener( - function(engineID, keyData) { + function (engineID, keyData) { + if (engineID === 'uk_extended_ime') { var handled = false; - + if (previousCharIsMagic && keyData.type == "keydown" && !isPureModifier(keyData)) { previousCharIsMagic = false; if (lut[keyData.key]) { - chrome.input.ime.commitText({"contextID": contextID, - "text": lut[keyData.key]}); + chrome.input.ime.commitText({ + "contextID": contextID, + "text": lut[keyData.key] + }); handled = true; } else { - chrome.input.ime.commitText({"contextID": contextID, - "text": "`"}); + chrome.input.ime.commitText({ + "contextID": contextID, + "text": "`" + }); } } - - if (!handled && keyData.type == "keydown" && keyData.code == "Backquote" && keyData.key =="`") { + + if (!handled && keyData.type == "keydown" && keyData.code == "Backquote" && keyData.key == "`") { previousCharIsMagic = true; handled = true; } - + return handled; -}); + } + else { // !uk_extended + if (keyData.type == 'keydown' && keyData.altKey) switch (keyData.key) { + case 'a': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ā' }); + return true; + case 'e': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ē' }); + return true; + case 'i': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ī' }); + return true; + case 'o': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ō' }); + return true; + case 'u': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ū' }); + return true; + default: + return false; + } + return false; + } + }); diff --git a/ukextended/manifest.json b/ukextended/manifest.json index f7a0184..fb83ff0 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -32,6 +32,14 @@ limitations under the License. "description": "UK extended keyboard (backquote acting as a dead key for grave accent", // user visible description "language": "en-GB", // The primary language this IME is used for "layouts": ["gb(extd)"] // The supported keyboard layouts for this IME (gb(extd) is actually a plain UK keyboard) + }, + { + "name": "English (NZ)", + "type": "ime", + "id": "english_nz", + "description": "NZ english keyboard (macron accent on right alt + vowel)", + "language": "en-US", + "layouts": ["us"] } ] } From b2bb788a951cdfe2d134bba01e1545c37ac79f7b Mon Sep 17 00:00:00 2001 From: John Palmer Date: Mon, 11 Dec 2023 10:47:35 +1100 Subject: [PATCH 2/8] fix description --- ukextended/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ukextended/manifest.json b/ukextended/manifest.json index fb83ff0..c0e0720 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ { - "name": "UK extended", + "name": "UK extended & English NZ", "version": "1.1", "manifest_version": 2, - "description": "UK extended keyboard (backquote acting as a dead key for grave accent)", + "description": "UK extended keyboard (backquote acting as a dead key for grave accent) and English NZ (macron available with right alt + vowel)", "background": { "scripts": ["background.js"] }, From bece81070387a4d33a0cdfc912420842fb6ab790 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Mon, 11 Dec 2023 11:29:20 +1100 Subject: [PATCH 3/8] Support for te reo --- ukextended/background.js | 76 +++++++++++++++++++++++++++++++++++++++- ukextended/manifest.json | 8 +++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/ukextended/background.js b/ukextended/background.js index 1ed1a9f..ecad6af 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -16,6 +16,7 @@ limitations under the License. var previousCharIsMagic = false; var contextID = -1; var lut = { "a": "à", "A": "À", "e": "è", "E": "È", "i": "ì", "I": "Ì", "o": "ò", "O": "Ò", "u": "ù", "U": "Ù", "w": "ẁ", "W": "Ẁ", "y": "ỳ", "Y": "Ỳ", "`": "`" }; +var usingTeReoLayout = false; chrome.input.ime.onFocus.addListener(function (context) { contextID = context.contextID; @@ -53,7 +54,7 @@ chrome.input.ime.onKeyEvent.addListener( return handled; } - else { // !uk_extended + else if (engineID === 'english_nz') { if (keyData.type == 'keydown' && keyData.altKey) switch (keyData.key) { case 'a': chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ā' }); @@ -75,4 +76,77 @@ chrome.input.ime.onKeyEvent.addListener( } return false; } + else { // Te reo + const teReoAltGrMapping = { + 'q': 'ka', + 'w': 'wh', + 'e': 'ē', + 'y': 'ū', + 'u': 'ū', + 'i': 'ī', + 'o': 'ō', + // row 2 + 'a': 'ā', + 's': 'te', + 'd': 'ē', + 'f': 'wh', + 'g': 'ng', + 'h': 'he', + 'j': 'ī', + 'k': 'ka', + 'l': 'ō', + // row 3, + 'z': 'ā', + 'x': 'ki', + 'c': 'ko', + 'v': 'ngā', + 'b': 'he' + } + + const teReoMapping = { + 'q': 'ka', + 'y': 'ū', + 's': 'te', + 'd': 'ē', + 'f': 'wh', + 'j': 'ī', + 'z': 'ā', + 'x': 'ki', + 'c': 'ko', + 'v': 'ngā', + 'b': 'he' + } + + // In both modes, the alt-gr layer is the same + if (keyData.type == 'keydown' && keyData.altKey && keyData.shiftKey && teReoAltGrMapping[keyData.key]) { + // Altgr+shift makes the keys uppercase. + const letters = teReoAltGrMapping[keyData.key]; + chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); + return true; + } + else if (keyData.type == 'keydown' && keyData.altKey && teReoAltGrMapping[keyData.key]) { + chrome.input.ime.commitText({ 'contextID': contextID, 'text': teReoAltGrMapping[keyData.key] }); + return true; + } + + if (usingTeReoLayout) { + if (keyData.type == 'keydown' && keyData.shiftKey && teReoMapping[keyData.key]) { + // Altgr+shift makes the keys uppercase. + const letters = teReoMapping[keyData.key]; + chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); + return true; + } + else if (keyData.type == 'keydown' && teReoMapping[keyData.key]) { + chrome.input.ime.commitText({ 'contextID': contextID, 'text': teReoMapping[keyData.key] }); + return true; + } + } + + if (keyData.key == '`') { + usingTeReoLayout = !usingTeReoLayout; + return true; + } + return false; + } + }); diff --git a/ukextended/manifest.json b/ukextended/manifest.json index c0e0720..66d655c 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -40,6 +40,14 @@ limitations under the License. "description": "NZ english keyboard (macron accent on right alt + vowel)", "language": "en-US", "layouts": ["us"] + }, + { + "name": "Te Reo", + "type": "ime", + "id": "te_reo", + "description": "Te Reo keyboard layout", + "language": "en-US", + "layouts": ["us"] } ] } From 04e64c0cc33e6020534ee1beb3c9f6de8b998795 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Mon, 11 Dec 2023 11:43:56 +1100 Subject: [PATCH 4/8] Fix up some typos --- ukextended/background.js | 45 +++++++++++++++++++++++----------------- ukextended/manifest.json | 4 ++-- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/ukextended/background.js b/ukextended/background.js index 1ed1a9f..16f2441 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -53,25 +53,32 @@ chrome.input.ime.onKeyEvent.addListener( return handled; } - else { // !uk_extended - if (keyData.type == 'keydown' && keyData.altKey) switch (keyData.key) { - case 'a': - chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ā' }); - return true; - case 'e': - chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ē' }); - return true; - case 'i': - chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ī' }); - return true; - case 'o': - chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ō' }); - return true; - case 'u': - chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ū' }); - return true; - default: - return false; + else { // NZ English + // Undo India keyboard map. + if (keyData.type === 'keydown' && keyData.shiftKey && keyData.code === 'Digit4') { + chrome.input.ime.commitText({ 'contextID': contextID, 'text': '$' }); + return true; + } + if (keyData.type === 'keydown' && keyData.altgrKey) { + switch (keyData.key) { + case 'a': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ā' }); + return true; + case 'e': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ē' }); + return true; + case 'i': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ī' }); + return true; + case 'o': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ō' }); + return true; + case 'u': + chrome.input.ime.commitText({ 'contextID': contextID, 'text': 'ū' }); + return true; + default: + return false; + } } return false; } diff --git a/ukextended/manifest.json b/ukextended/manifest.json index c0e0720..51c282b 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -38,8 +38,8 @@ limitations under the License. "type": "ime", "id": "english_nz", "description": "NZ english keyboard (macron accent on right alt + vowel)", - "language": "en-US", - "layouts": ["us"] + "language": "en-us", + "layouts": ["in(eng)"] // in(eng) is qwerty but with rupee sign instead of dollar, but includes a right-alt layer which we need } ] } From c912c4851f8e0c3bb55c6dfb71004836ae5d7acd Mon Sep 17 00:00:00 2001 From: John Palmer Date: Mon, 11 Dec 2023 12:01:57 +1100 Subject: [PATCH 5/8] fix typos --- ukextended/background.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ukextended/background.js b/ukextended/background.js index a855dc5..1d410bb 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -55,9 +55,9 @@ chrome.input.ime.onKeyEvent.addListener( return handled; } else if (engineID === 'english_nz') { - // Undo India keyboard map. - if (keyData.type === 'keydown' && keyData.shiftKey && keyData.code === 'Digit4') { - chrome.input.ime.commitText({ 'contextID': contextID, 'text': '$' }); + // undo india keyboard map. + if (keyData.type === 'keydown' && keyData.shiftkey && keyData.code === 'digit4') { + chrome.input.ime.committext({ 'contextid': contextid, 'text': '$' }); return true; } if (keyData.type === 'keydown' && keyData.altgrKey) { @@ -84,6 +84,12 @@ chrome.input.ime.onKeyEvent.addListener( return false; } else { // Te reo + // undo india keyboard map. + if (keyData.type === 'keydown' && keyData.shiftkey && keyData.code === 'digit4') { + chrome.input.ime.committext({ 'contextid': contextid, 'text': '$' }); + return true; + } + const teReoAltGrMapping = { 'q': 'ka', 'w': 'wh', @@ -125,19 +131,19 @@ chrome.input.ime.onKeyEvent.addListener( } // In both modes, the alt-gr layer is the same - if (keyData.type == 'keydown' && keyData.altKey && keyData.shiftKey && teReoAltGrMapping[keyData.key]) { + if (keyData.type === 'keydown' && keyData.altgrKey && keyData.shiftKey && teReoAltGrMapping[keyData.key]) { // Altgr+shift makes the keys uppercase. const letters = teReoAltGrMapping[keyData.key]; chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); return true; } - else if (keyData.type == 'keydown' && keyData.altKey && teReoAltGrMapping[keyData.key]) { + else if (keyData.type === 'keydown' && keyData.altgrKey && teReoAltGrMapping[keyData.key]) { chrome.input.ime.commitText({ 'contextID': contextID, 'text': teReoAltGrMapping[keyData.key] }); return true; } if (usingTeReoLayout) { - if (keyData.type == 'keydown' && keyData.shiftKey && teReoMapping[keyData.key]) { + if (keyData.type === 'keydown' && keyData.shiftKey && teReoMapping[keyData.key]) { // Altgr+shift makes the keys uppercase. const letters = teReoMapping[keyData.key]; chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); @@ -149,7 +155,7 @@ chrome.input.ime.onKeyEvent.addListener( } } - if (keyData.key == '`') { + if (keyData.type === 'keydown' && keyData.key === '`') { usingTeReoLayout = !usingTeReoLayout; return true; } From 8b6f6e80a9ab3e0efd508262df2fb166338abf41 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Wed, 20 Dec 2023 10:01:13 +1100 Subject: [PATCH 6/8] Add Te Reo for g/l --- ukextended/background.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ukextended/background.js b/ukextended/background.js index 1d410bb..9662384 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -89,7 +89,7 @@ chrome.input.ime.onKeyEvent.addListener( chrome.input.ime.committext({ 'contextid': contextid, 'text': '$' }); return true; } - + const teReoAltGrMapping = { 'q': 'ka', 'w': 'wh', @@ -122,7 +122,9 @@ chrome.input.ime.onKeyEvent.addListener( 's': 'te', 'd': 'ē', 'f': 'wh', + 'g': 'ng', 'j': 'ī', + 'l': 'ō', 'z': 'ā', 'x': 'ki', 'c': 'ko', From 6af69a874b22b9743f8f27df6adad8c20a9ff6fd Mon Sep 17 00:00:00 2001 From: John Palmer Date: Wed, 20 Dec 2023 10:20:29 +1100 Subject: [PATCH 7/8] rm JSON comments --- ukextended/background.js | 8 ++++---- ukextended/manifest.json | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ukextended/background.js b/ukextended/background.js index 9662384..33dda71 100644 --- a/ukextended/background.js +++ b/ukextended/background.js @@ -133,9 +133,9 @@ chrome.input.ime.onKeyEvent.addListener( } // In both modes, the alt-gr layer is the same - if (keyData.type === 'keydown' && keyData.altgrKey && keyData.shiftKey && teReoAltGrMapping[keyData.key]) { + if (keyData.type === 'keydown' && keyData.altgrKey && keyData.shiftKey && teReoAltGrMapping[keyData.key.toLowerCase()]) { // Altgr+shift makes the keys uppercase. - const letters = teReoAltGrMapping[keyData.key]; + const letters = teReoAltGrMapping[keyData.key.toLowerCase()]; chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); return true; } @@ -145,9 +145,9 @@ chrome.input.ime.onKeyEvent.addListener( } if (usingTeReoLayout) { - if (keyData.type === 'keydown' && keyData.shiftKey && teReoMapping[keyData.key]) { + if (keyData.type === 'keydown' && keyData.shiftKey && teReoMapping[keyData.key.toLowerCase()]) { // Altgr+shift makes the keys uppercase. - const letters = teReoMapping[keyData.key]; + const letters = teReoMapping[keyData.key.toLowerCase()]; chrome.input.ime.commitText({ 'contextID': contextID, 'text': letters.charAt(0).toUpperCase() + letters.slice(1) }); return true; } diff --git a/ukextended/manifest.json b/ukextended/manifest.json index 9f160ea..89e46c2 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -29,9 +29,9 @@ limitations under the License. "name": "UK extended", "type": "ime", "id": "uk_extended_ime", - "description": "UK extended keyboard (backquote acting as a dead key for grave accent", // user visible description - "language": "en-GB", // The primary language this IME is used for - "layouts": ["gb(extd)"] // The supported keyboard layouts for this IME (gb(extd) is actually a plain UK keyboard) + "description": "UK extended keyboard (backquote acting as a dead key for grave accent", + "language": "en-GB", + "layouts": ["gb(extd)"] }, { "name": "English (NZ)", @@ -39,7 +39,7 @@ limitations under the License. "id": "english_nz", "description": "NZ english keyboard (macron accent on right alt + vowel)", "language": "en-US", - "layouts": ["in(eng)"] // in(eng) is qwerty but with rupee sign instead of dollar, but includes a right-alt layer which we need + "layouts": ["in(eng)"] }, { "name": "Te Reo", @@ -47,7 +47,7 @@ limitations under the License. "id": "te_reo", "description": "Te Reo keyboard layout", "language": "en-US", - "layouts": ["in(eng)"] // in(eng) is qwerty but with rupee sign instead of dollar, but includes a right-alt layer which we need + "layouts": ["in(eng)"] } ] } From 40b38a55d02afae34a80c4cdf514888d662dc7c4 Mon Sep 17 00:00:00 2001 From: John Palmer Date: Wed, 20 Dec 2023 10:41:55 +1100 Subject: [PATCH 8/8] Fix to get things published --- ukextended/manifest.json | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/ukextended/manifest.json b/ukextended/manifest.json index 89e46c2..f0dec43 100644 --- a/ukextended/manifest.json +++ b/ukextended/manifest.json @@ -1,21 +1,6 @@ -/* -Copyright 2014 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ { - "name": "UK extended & English NZ", - "version": "1.1", + "name": "UK extended, English NZ & Te Reo", + "version": "2.0", "manifest_version": 2, "description": "UK extended keyboard (backquote acting as a dead key for grave accent) and English NZ (macron available with right alt + vowel)", "background": {