Skip to content

Commit 90f5ab6

Browse files
committed
chore(developer): fix tests for layout validity
The tests for layout validity in #9087 were incomplete; first, they didn't fail the build if a key had invalid identifier, and second, there were some constants missing from the KeyIdType test (imperfect translation from the Delphi code in this case).
1 parent b5a1e13 commit 90f5ab6

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

developer/src/kmc-kmn/src/kmw-compiler/keymanweb-key-codes.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,29 @@ export const enum
819819
K_ALTGR = 50010,
820820
K_TABBACK = 50011,
821821
K_TABFWD = 50012
822-
};
822+
};
823+
824+
export const KeymanWebTouchStandardKeyNames: string[] = [
825+
'K_LOPT',
826+
'K_ROPT',
827+
'K_NUMERALS',
828+
'K_SYMBOLS',
829+
'K_CURRENCIES',
830+
'K_UPPER',
831+
'K_LOWER',
832+
'K_ALPHA',
833+
'K_SHIFTED',
834+
'K_ALTGR',
835+
'K_TABBACK',
836+
'K_TABFWD',
837+
];
838+
839+
/**
840+
* Used only by KMW
841+
*/
842+
export const KMWAdditionalKeyNames: string[] = [
843+
'K_LCONTROL',
844+
'K_RCONTROL',
845+
'K_LALT',
846+
'K_RALT',
847+
];

developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { KMX, Osk, TouchLayout, TouchLayoutFileReader, TouchLayoutFileWriter } f
22
import { callbacks, IsKeyboardVersion14OrLater, IsKeyboardVersion15OrLater } from "./compiler-globals.js";
33
import { JavaScript_Key } from "./javascript-strings.js";
44
import { TRequiredKey, CRequiredKeys, CSpecialText10, CSpecialText14, CSpecialText14ZWNJ, CSpecialText14Map } from "./constants.js";
5-
import { VKeyNames } from "./keymanweb-key-codes.js";
5+
import { KeymanWebTouchStandardKeyNames, KMWAdditionalKeyNames, VKeyNames } from "./keymanweb-key-codes.js";
66
import { KmwCompilerMessages } from "./messages.js";
77

88

@@ -45,6 +45,14 @@ function KeyIdType(FId: string): TKeyIdType { // I4142
4545
if(VKeyNames.find(key => key.toUpperCase() == FId)) {
4646
return TKeyIdType.Key_Constant;
4747
}
48+
49+
if(KeymanWebTouchStandardKeyNames.indexOf(FId) >= 0) {
50+
return TKeyIdType.Key_Constant;
51+
}
52+
53+
if(KMWAdditionalKeyNames.indexOf(FId) >= 0) {
54+
return TKeyIdType.Key_Constant;
55+
}
4856
}
4957
return TKeyIdType.Key_Invalid;
5058
}
@@ -60,7 +68,7 @@ function CheckKey(
6068
FKeyType: TouchLayout.TouchLayoutKeySp,
6169
FRequiredKeys: TRequiredKey[],
6270
FDictionary: string[]
63-
) { // I4119
71+
): boolean { // I4119
6472

6573
//
6674
// Check that each touch layer has K_LOPT, [K_ROPT,] K_BKSP, K_ENTER
@@ -96,16 +104,18 @@ function CheckKey(
96104
if(!(FKeyType in [TouchLayout.TouchLayoutKeySp.blank, TouchLayout.TouchLayoutKeySp.spacer]) && FNextLayer == '') {
97105
callbacks.reportMessage(KmwCompilerMessages.Warn_TouchLayoutUnidentifiedKey({layerId: layer.id}));
98106
}
99-
return;
107+
return true;
100108
}
101109

102110
let FValid = KeyIdType(FId);
103111

104112
if(FValid == TKeyIdType.Key_Invalid) {
105113
callbacks.reportMessage(KmwCompilerMessages.Error_TouchLayoutInvalidIdentifier({keyId: FId, platformName: platformId, layerId: layer.id}));
114+
return false;
106115
}
107116
else if (FValid == TKeyIdType.Key_Unicode_Multi && !IsKeyboardVersion15OrLater()) {
108117
callbacks.reportMessage(KmwCompilerMessages.Error_TouchLayoutIdentifierRequires15({keyId: FId, platformName: platformId, layerId: layer.id}));
118+
return false;
109119
}
110120

111121
//
@@ -138,6 +148,8 @@ function CheckKey(
138148
}));
139149
}
140150
}
151+
152+
return true;
141153
}
142154

143155
function CheckDictionaryKeyValidity(fk: KMX.KEYBOARD, FDictionary: string[]) { // I4142
@@ -196,6 +208,7 @@ export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFil
196208
return {output:null, result: false};
197209
}
198210

211+
let result: boolean = true;
199212
let FTouchLayoutFont = ''; // I4872
200213
let pid: keyof TouchLayout.TouchLayoutFile;
201214
for(pid in data) {
@@ -216,23 +229,23 @@ export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFil
216229
let FRequiredKeys: TRequiredKey[] = [];
217230
for(let row of layer.row) {
218231
for(let key of row.key) {
219-
CheckKey(pid, platform, layer, key.id, key.text, key.nextlayer, key.sp, FRequiredKeys, FDictionary); // I4119
232+
result = CheckKey(pid, platform, layer, key.id, key.text, key.nextlayer, key.sp, FRequiredKeys, FDictionary) && result; // I4119
220233
if(key.sk) {
221234
for(let subkey of key.sk) {
222-
CheckKey(pid, platform, layer, subkey.id, subkey.text, subkey.nextlayer, subkey.sp, FRequiredKeys, FDictionary);
235+
result = CheckKey(pid, platform, layer, subkey.id, subkey.text, subkey.nextlayer, subkey.sp, FRequiredKeys, FDictionary) && result;
223236
}
224237
}
225238
let direction: keyof TouchLayout.TouchLayoutFlick;
226239
if(key.flick) {
227240
for(direction in key.flick) {
228-
CheckKey(pid, platform, layer, key.flick[direction].id, key.flick[direction].text,
229-
key.flick[direction].nextlayer, key.flick[direction].sp, FRequiredKeys, FDictionary);
241+
result = CheckKey(pid, platform, layer, key.flick[direction].id, key.flick[direction].text,
242+
key.flick[direction].nextlayer, key.flick[direction].sp, FRequiredKeys, FDictionary) && result;
230243
}
231244
}
232245

233246
if(key.multitap) {
234247
for(let subkey of key.multitap) {
235-
CheckKey(pid, platform, layer, subkey.id, subkey.text, subkey.nextlayer, subkey.sp, FRequiredKeys, FDictionary);
248+
result = CheckKey(pid, platform, layer, subkey.id, subkey.text, subkey.nextlayer, subkey.sp, FRequiredKeys, FDictionary) && result;
236249
}
237250
}
238251
}
@@ -263,6 +276,6 @@ export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFil
263276

264277
return {
265278
output: sLayoutFile,
266-
result: true
279+
result
267280
}
268281
}

0 commit comments

Comments
 (0)