fix(developer): find last matching key in LDML key bag when building KVK

Fixes: #12056
This commit is contained in:
Marc Durdin 2024-08-24 00:15:33 +02:00
parent 3b10dcde5f
commit d028124ca9

View file

@ -3,6 +3,23 @@ import { LDMLKeyboard, CompilerCallbacks } from "@keymanapp/developer-utils";
import { KeysCompiler } from "./keys.js";
import { LdmlCompilerMessages } from "./ldml-compiler-messages.js";
// This is a partial polyfill for findLast, so not polluting Array.prototype
//
// TODO: remove and replace with Array.prototype.findLast when it is
// well-supported
function findLast(arr: any, callback: any) {
if (!arr) {
return undefined;
}
const len = arr.length >>> 0;
for (let i = len - 1; i >= 0; i--) {
if (callback(arr[i], i, arr)) {
return arr[i];
}
}
return undefined;
}
export class LdmlKeyboardVisualKeyboardCompiler {
public constructor(private callbacks: CompilerCallbacks) {
}
@ -57,7 +74,8 @@ export class LdmlKeyboardVisualKeyboardCompiler {
const keyId = key;
x++;
let keydef = source.keyboard3.keys?.key?.find(x => x.id == key);
//@ts-ignore
let keydef = findLast(source.keyboard3.keys?.key, x => x.id == key);
if (!keydef) {
this.callbacks.reportMessage(