mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-21 07:07:39 +00:00
fix(developer): find last matching key in LDML key bag when building KVK
Fixes: #12056
This commit is contained in:
parent
3b10dcde5f
commit
d028124ca9
1 changed files with 19 additions and 1 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue