From 7cbb78ea45dd2abdc3240de17a5b8eeed085f96d Mon Sep 17 00:00:00 2001 From: jahorton Date: Wed, 17 Mar 2021 10:26:58 +0700 Subject: [PATCH] fix(web): uses new IDs as needed outside of web-core --- web/source/kmwembedded.ts | 6 +++--- web/source/osk/preProcessor.ts | 8 +++++++- web/source/osk/visualKeyboard.ts | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/web/source/kmwembedded.ts b/web/source/kmwembedded.ts index 5ad82f52d5..c17bb43037 100644 --- a/web/source/kmwembedded.ts +++ b/web/source/kmwembedded.ts @@ -402,14 +402,14 @@ namespace com.keyman.text { var baseKey: com.keyman.osk.OSKKeySpec = osk.vkbd.popupBaseKey['key'].spec; var found = false; - if(baseKey.id == keyName) { + if(baseKey.coreID == keyName) { nextLayer = baseKey.nextlayer; found = true; } else { // Search for the specified subkey so we can retrieve its useful properties. // It should be within the popupBaseKey's subkey list. for(let subKey of baseKey.sk) { - if(subKey.id == keyName) { + if(subKey.coreID == keyName) { // ... to consider: why are we not just taking the keyspec wholesale right here? nextLayer = subKey.nextlayer; found = true; @@ -419,7 +419,7 @@ namespace com.keyman.text { } if(!found) { - console.warn("Could not find subkey '" + origArg + "' under the current base key '" + baseKey.id + "'!"); + console.warn("Could not find subkey '" + origArg + "' under the current base key '" + baseKey.coreID + "'!"); } } else { console.warn("No base key exists for the subkey being executed: '" + origArg + "'"); diff --git a/web/source/osk/preProcessor.ts b/web/source/osk/preProcessor.ts index 64469b6ed6..e8174a05cb 100644 --- a/web/source/osk/preProcessor.ts +++ b/web/source/osk/preProcessor.ts @@ -48,7 +48,13 @@ namespace com.keyman.osk { // Deleting matched deadkeys here seems to correct some of the issues. (JD 6/6/14) outputTarget.deadkeys().deleteMatched(); // Delete any matched deadkeys before continuing - let keySpec = (e['key'] ? e['key'].spec : null) as keyboards.ActiveKey; + // Future note: we need to refactor osk.OSKKeySpec to instead be a 'tag field' for + // keyboards.ActiveKey. (Prob with generics, allowing the Web-only parts to + // be fully specified within the tag.) + // + // Would avoid the type shenanigans needed here because of our current type-abuse setup + // for key spec tracking. + let keySpec = (e['key'] ? e['key'].spec : null) as unknown as keyboards.ActiveKey; if(!keySpec) { console.error("OSK key with ID '" + e.id + "', keyID '" + e.keyId + "' missing needed specification"); return true; diff --git a/web/source/osk/visualKeyboard.ts b/web/source/osk/visualKeyboard.ts index 131cd83275..1af1f140d6 100644 --- a/web/source/osk/visualKeyboard.ts +++ b/web/source/osk/visualKeyboard.ts @@ -46,6 +46,12 @@ namespace com.keyman.osk { //#region OSK key objects and construction export class OSKKeySpec implements keyboards.LayoutKey { id: string; + + // Only set (within @keymanapp/keyboard-processor) for keys actually specified in a loaded layout + baseKeyIdentifier?: string; + coreID?: string; + elementID?: string; + text?: string; sp?: number | keyboards.ButtonClass; width: string; @@ -317,13 +323,13 @@ namespace com.keyman.osk { getId(osk: VisualKeyboard): string { // Define each key element id by layer id and key id (duplicate possible for SHIFT - does it matter?) - return this.layer+'-'+this.spec.id; + return this.spec.elementID; } // Produces a small reference label for the corresponding physical key on a US keyboard. private generateKeyCapLabel(): HTMLDivElement { // Create the default key cap labels (letter keys, etc.) - var x = Codes.keyCodes[this.spec.id]; + var x = Codes.keyCodes[this.spec.baseKeyIdentifier]; switch(x) { // Converts the keyman key id code for common symbol keys into its representative ASCII code. // K_COLON -> K_BKQUOTE @@ -1766,7 +1772,11 @@ namespace com.keyman.osk { // bk = skElement; // break; //} else - if(skSpec.id == baseKey.keyId && skSpec.layer == baseKey.key.layer) { + if(!baseKey.key || !baseKey.key.spec) { + continue; + } + + if(skSpec.elementID == baseKey.key.spec.elementID) { bk = skElement; break; // Best possible match has been found. (Disable 'break' once above block is implemented.) }