From d028124ca993e307d592b15f8e4e6c7fd2d74044 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Sat, 24 Aug 2024 00:15:33 +0200 Subject: [PATCH 1/2] fix(developer): find last matching key in LDML key bag when building KVK Fixes: #12056 --- .../src/compiler/visual-keyboard-compiler.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts index 6182e6e2c8f..4c51078af85 100644 --- a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts +++ b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts @@ -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( From 6353f926ba31f8d776a05cfd395770f580cd2dfd Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 26 Aug 2024 09:09:00 +0200 Subject: [PATCH 2/2] chore: Update developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts --- developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts index 4c51078af85..6d76bc403ea 100644 --- a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts +++ b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts @@ -4,7 +4,7 @@ import { KeysCompiler } from "./keys.js"; import { LdmlCompilerMessages } from "./ldml-compiler-messages.js"; // This is a partial polyfill for findLast, so not polluting Array.prototype -// +// https://medium.com/@stheodorejohn/findlast-method-polyfill-in-javascript-bridging-browser-gaps-c3baf6aabae1 // TODO: remove and replace with Array.prototype.findLast when it is // well-supported function findLast(arr: any, callback: any) {