Skip to content

Commit

Permalink
fix(developer): vis kbd callbacks instead of throw 🙀
Browse files Browse the repository at this point in the history
- fix API and call sites

For: #9438
  • Loading branch information
srl295 committed Nov 10, 2023
1 parent beb54bf commit 1763e6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions developer/src/kmc-ldml/src/compiler/keymanweb-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class LdmlKeyboardKeymanWebCompiler {
private readonly options: LdmlCompilerOptions;
private readonly nl: string;
private readonly tab: string;

constructor(private callbacks: CompilerCallbacks, options?: LdmlCompilerOptions) {
this.options = { ...options };
this.nl = this.options.saveDebug ? "\n" : '';
Expand All @@ -18,7 +17,7 @@ export class LdmlKeyboardKeymanWebCompiler {

public compileVisualKeyboard(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile) {
const nl = this.nl, tab = this.tab;
const vkc = new LdmlKeyboardVisualKeyboardCompiler();
const vkc = new LdmlKeyboardVisualKeyboardCompiler(this.callbacks);
const vk: VisualKeyboard.VisualKeyboard = vkc.compile(source);

let result =
Expand Down
31 changes: 21 additions & 10 deletions developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { VisualKeyboard, LDMLKeyboard } from "@keymanapp/common-types";
import { VisualKeyboard, LDMLKeyboard, CompilerCallbacks } from "@keymanapp/common-types";
import { KeysCompiler } from "./keys.js";
import { CompilerMessages } from "./messages.js";

export class LdmlKeyboardVisualKeyboardCompiler {
public constructor(private callbacks: CompilerCallbacks) {
}

public compile(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): VisualKeyboard.VisualKeyboard {
let result = new VisualKeyboard.VisualKeyboard();

Expand Down Expand Up @@ -29,12 +33,16 @@ export class LdmlKeyboardVisualKeyboardCompiler {
layer: LDMLKeyboard.LKLayer,
hardware: string,
) {
const layerId = layer.id;
if (hardware === 'touch') {
hardware = 'us'; // TODO-LDML: US Only. Do something different here?
}
const keymap = KeysCompiler.getKeymapFromForms(source.keyboard3?.forms?.form, hardware);
if (!keymap) {
throw Error(`Internal error: could not find keymap for form ${hardware}`);
this.callbacks.reportMessage(
CompilerMessages.Error_InvalidHardware({ formId: hardware })
);
return;
}
const shift = this.translateLayerIdToVisualKeyboardShift(layer.id);

Expand All @@ -45,20 +53,23 @@ export class LdmlKeyboardVisualKeyboardCompiler {
const keys = row.keys.split(' ');
let x = -1;
for(let key of keys) {
const keyId = key;
x++;

let keydef = source.keyboard3.keys?.key?.find(x => x.id == key);

if (!keydef) {
throw Error(`Internal Error: could not find key id="${key}" in layer "${layer.id || '<none>'}", row "${y}"`);
this.callbacks.reportMessage(
CompilerMessages.Error_KeyNotFoundInKeyBag({ keyId, layer: layerId, row: y, col: x, form: hardware })
);
} else {
vk.keys.push({
flags: VisualKeyboard.VisualKeyboardKeyFlags.kvkkUnicode,
shift: shift,
text: keydef.output, // TODO-LDML: displays
vkey: keymap[y][x],
});
}

vk.keys.push({
flags: VisualKeyboard.VisualKeyboardKeyFlags.kvkkUnicode,
shift: shift,
text: keydef.output, // TODO-LDML: displays
vkey: keymap[y][x],
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-ldml/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function compileVisualKeyboard(inputFilename: string, options: LdmlCompil
checkMessages();
assert.isTrue(valid, 'k.validate should not have failed');

const vk = (new LdmlKeyboardVisualKeyboardCompiler()).compile(source);
const vk = (new LdmlKeyboardVisualKeyboardCompiler(compilerTestCallbacks)).compile(source);
checkMessages();
assert.isNotNull(vk, 'LdmlKeyboardVisualKeyboardCompiler.compile should not have returned null');

Expand Down

0 comments on commit 1763e6a

Please sign in to comment.