Skip to content

Commit

Permalink
Merge pull request #10236 from keymanapp/feat/developer/9451-key-not-…
Browse files Browse the repository at this point in the history
…found-epic-ldml

feat(developer): ldml: more improvement for key-not-found 🙀
  • Loading branch information
srl295 authored Dec 20, 2023
2 parents a5957cc + 094f5ad commit 7d9eca1
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 45 deletions.
14 changes: 13 additions & 1 deletion common/tools/hextobin/hextobin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ function exitDueToUsageError(message: string): never {
return process.exit(64); // SysExits.EX_USAGE
}

hextobin(inputFilename, outputFilename, {silent: false});
hextobin(inputFilename, outputFilename, { silent: false })
.then((buffer) => {
if (buffer) {
process.exit(0); // OK
} else {
console.error(`${program._name}: Failed.`);
process.exit(1); // no buffer - some err.
}
}, (err) => {
console.error(err);
console.error(`${program._name}: Failed.`);
process.exit(1);
});
3 changes: 1 addition & 2 deletions core/src/ldml/ldml_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ ldml_processor::process_key_down(km_core_state *state, km_core_virtual_key vk, u
// no key was found, so pass the keystroke on to the Engine
emit_invalidate_passthrough_keystroke(state, vk, modifier_state);
} else if (!key_str.empty()) {
// TODO-LDML: Right now we take no action on empty (i.e. gap) keys. Should we take other action?
process_key_string(state, key_str);
}
} // else no action: It's a gap or gap-like key.
}

void
Expand Down
2 changes: 1 addition & 1 deletion core/tests/unit/ldml/ldml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ apply_action(
assert(context.back().character == ch);
context.pop_back();
} else {
// assume it's otherwise KM-coRE_BT_UNKNOWN
// assume it's otherwise KM_CORE_BT_UNKNOWN
assert(act.backspace.expected_type == KM_CORE_BT_UNKNOWN);
assert(context.empty()); // if KM_CORE_BT_UNKNOWN, context should be empty.
}
Expand Down
78 changes: 66 additions & 12 deletions developer/src/kmc-ldml/src/compiler/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { SectionCompiler } from "./section-compiler.js";

import DependencySections = KMXPlus.DependencySections;
import Keys = KMXPlus.Keys;
import KeysKeys = KMXPlus.KeysKeys;
import ListItem = KMXPlus.ListItem;
import KeysFlicks = KMXPlus.KeysFlicks;
import { allUsedKeyIdsInFlick, allUsedKeyIdsInKey, allUsedKeyIdsInLayers, calculateUniqueKeys, hashFlicks, hashKeys, translateLayerAttrToModifier, validModifier } from '../util/util.js';
import { MarkerTracker, MarkerUse } from './marker-tracker.js';

/** reserved name for the special gap key. space is not allowed in key ids. */
const reserved_gap = "gap (reserved)";


export class KeysCompiler extends SectionCompiler {
static validateMarkers(
keyboard: LDMLKeyboard.LKKeyboard,
Expand Down Expand Up @@ -193,9 +198,48 @@ export class KeysCompiler extends SectionCompiler {
}
} // else: TODO-LDML do nothing if only touch layers

// Now load the reserved keys and slip them in here
const reservedKeys = this.getReservedKeys(sections);
for (const key of reservedKeys.values()) {
sect.keys.push(key);
}

return sect;
}

/** list of reserved keys, for tests */
public static readonly reserved_keys = [ reserved_gap ];
/** count of reserved keys, for tests */
public static readonly reserved_count = KeysCompiler.reserved_keys.length;

/** load up all reserved keys */
getReservedKeys(sections: KMXPlus.DependencySections) : Map<String, KeysKeys> {
const r = new Map<String, KeysKeys>();

// set up some constants..
const no_string = sections.strs.allocString('');
const no_list = sections.list.allocList([], {}, sections);

// now add the reserved key(s).
r.set(reserved_gap, {
flags: constants.keys_key_flags_gap | constants.keys_key_flags_extend,
id: sections.strs.allocString(reserved_gap),
flicks: '',
longPress: no_list,
longPressDefault: no_string,
multiTap: no_list,
switch: no_string,
to: no_string,
width: 10.0, // 10 * .1
});

if (r.size !== KeysCompiler.reserved_count) {
throw Error(`Internal Error: KeysCompiler.reserved_count=${KeysCompiler.reserved_count} != ${r.size} actual reserved keys.`);
}

return r;
}

static addUsedGestureKeys(layerKeyIds: string[], keyBag: Map<string, LDMLKeyboard.LKKey>, usedKeys: Set<string>) {
for (let keyId of layerKeyIds) {
const key = keyBag.get(keyId);
Expand Down Expand Up @@ -436,22 +480,32 @@ export class KeysCompiler extends SectionCompiler {
const mod = translateLayerAttrToModifier(layer);
const keymap = this.getKeymapFromForm(hardware);

let y = -1;
for (let row of layer.row) {
y++;
// Iterate over rows (y) and cols (x) of the scancodes table.
// Any assigned keys will be used until we run out of keys in each row,
// and run out of rows. The rest will be reserved_gap.

const keys = row.keys.split(" ");
let x = -1;
for (let key of keys) {
x++;
for (let y = 0; y < keymap.length; y++) {
let keys : string[];

// if there are keys, use them.
if (y < layer.row.length ) {
const row = layer.row[y];
keys = row.keys.split(" ");
} else {
keys = [];
}

// TODO-LDML: we already validated that the key exists, above.
// So here we only need the ID?
// let keydef = this.keyboard3.keys?.key?.find(x => x.id == key);
// all columns in this row
for (let x = 0; x < keymap[y].length; x++) {
const vkey = keymap[y][x]; // from the scan table

let key = reserved_gap; // unless there's a key in this row
if (x < keys.length) {
key = keys[x];
}
sect.kmap.push({
vkey: keymap[y][x],
mod: mod,
vkey,
mod,
key, // key id, to be changed into key index at finalization
});
}
Expand Down
105 changes: 88 additions & 17 deletions developer/src/kmc-ldml/test/fixtures/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ block(endelem)
block(keys) # struct COMP_KMXPLUS_KEYS {
6b 65 79 73 # KMX_DWORD header.ident; // 0000 Section name - keys
sizeof(keys) # KMX_DWORD header.size; // 0004 Section length
04 00 00 00 # KMX_DWORD keyCount
05 00 00 00 # KMX_DWORD keyCount
01 00 00 00 # KMX_DWORD flicksCount
00 00 00 00 # KMX_DWORD flickCount
02 00 00 00 # KMX_DWORD kmapCount; // 0008 number of kmap
30 00 00 00 # KMX_DWORD kmapCount; // 0008 number of kmap - #48, one per key
# keys
# (#0000) a
61 00 00 00 # 'a'
00 00 00 00 # KMX_DWORD flags = extend
00 00 00 00 # KMX_DWORD flags = 0
index(strNull,strA,2) # KMXPLUS_STR 'a' (key id)
00 00 00 00 # KMXPLUS_STR switch
0A 00 00 00 # KMX_DWORD width*10
Expand All @@ -263,15 +263,25 @@ block(keys) # struct COMP_KMXPLUS_KEYS {
00 00 00 00 # flicks
# (#0001) e
65 00 00 00 # 'e'
00 00 00 00 # KMX_DWORD flags = extend
00 00 00 00 # KMX_DWORD flags = 0
index(strNull,strElemBkspFrom2,2) # KMXPLUS_STR 'e' (key id)
00 00 00 00 # KMXPLUS_STR switch
0A 00 00 00 # KMX_DWORD width*10
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST longPress
00 00 00 00 # STR longPressDefault
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST multiTap
00 00 00 00 # flicks
# (#0002) hmaqtugha
# (#0002) gap (reserved)
00 00 00 00 # nothing
03 00 00 00 # KMX_DWORD flags = extend|gap
index(strNull,strGapReserved,2) # KMXPLUS_STR 'gap (reserved)' (key id)
00 00 00 00 # KMXPLUS_STR switch
0A 00 00 00 # KMX_DWORD width*10 (full width)
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST longPress
00 00 00 00 # STR longPressDefault
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST multiTap
00 00 00 00 # flicks
# (#0003) hmaqtugha
27 01 00 00 # UTF-32 'U+0127'
00 00 00 00 # KMX_DWORD (flags: none)
index(strNull,strHmaqtugha,2) # KMXPLUS_STR 'hmaqtugha'
Expand All @@ -281,10 +291,10 @@ block(keys) # struct COMP_KMXPLUS_KEYS {
00 00 00 00 # STR longPressDefault
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST multiTap
00 00 00 00 # flicks 0
# (#0003) that
index(strNull,strKeys,2) # KMXPLUS_STR 'U+0127'
# (#0004) that
index(strNull,strKeys,2) # KMXPLUS_STR '...'
01 00 00 00 # KMX_DWORD flags = extend
index(strNull,strThat,2) # KMXPLUS_STR 'hmaqtugha'
index(strNull,strThat,2) # KMXPLUS_STR 'that'
00 00 00 00 # KMXPLUS_STR switch
0A 00 00 00 # KMX_DWORD width*10
00 00 00 00 # TODO: index(listNull,listNull,4) # LIST longPress
Expand All @@ -305,16 +315,75 @@ block(keys) # struct COMP_KMXPLUS_KEYS {
# kmapdata:
# note that 'a' and 'e' are omitted, as they aren't on the layers (just from gestures)

# #0
31 00 00 00 # KMX_DWORD vkey
00 00 00 00 # KMX_DWORD modifiers (none)
03 00 00 00 # KMX_DWORD key index (that)

# #1
c0 00 00 00 # KMX_DWORD vkey
00 00 00 00 # KMX_DWORD modifiers (none)
02 00 00 00 # KMX_DWORD key index (hmaqtugha)
# moving these to 1-liners so they can be sorted! the structure is as follows:
## 31 00 00 00 # KMX_DWORD vkey
## 00 00 00 00 # KMX_DWORD modifiers (none)
## 04 00 00 00 # KMX_DWORD key index (that)

# following lines generated with this snippet:
#
# /** from scanCodes-implied.xml */
# const scans = ("29 02 03 04 05 06 07 08 09 0A 0B 0C 0D" + " 10 11 12 13 14 15 16 17 18 19 1A 1B 2B" + " 1E 1F 20 21 22 23 24 25 26 27 28" + " 2C 2D 2E 2F 30 31 32 33 34 35").split(/ /);
#
# for (let s of scans) {
# const n = Number.parseInt(s, 16);
# const v = CLDRScanToUSVirtualKeyCodes[n]; // virtual-key-constants.ts
# if (!v) {
# console.error(`! ${s}`);
# } else {
# console.log(` ${Number(v).toString(16)} 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)`);
# }
# }

# - vkey - - modifier - - key id -
20 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
30 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
31 00 00 00 00 00 00 00 04 00 00 00 # "that"
32 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
33 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
34 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
35 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
36 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
37 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
38 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
39 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
41 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
42 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
43 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
44 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
45 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
46 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
47 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
48 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
49 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4a 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4b 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4c 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4d 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4e 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
4f 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
50 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
51 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
52 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
53 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
54 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
55 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
56 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
57 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
58 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
59 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
5a 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
ba 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
bb 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
bc 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
bd 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
be 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
bf 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
c0 00 00 00 00 00 00 00 03 00 00 00 # "hmaqtugha"
db 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
dc 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
dd 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)
de 00 00 00 00 00 00 00 02 00 00 00 # gap (reserved)

# ----------------------------------------------------------------------------------------------------
# layr
Expand Down Expand Up @@ -432,6 +501,7 @@ block(strs) # struct COMP_KMXPLUS_STRS {
diff(strs,strSet2) sizeof(strSet2,2)
diff(strs,strBase) sizeof(strBase,2)
diff(strs,strElemBkspFrom2) sizeof(strElemBkspFrom2,2)
diff(strs,strGapReserved) sizeof(strGapReserved,2)
diff(strs,strHmaqtugha) sizeof(strHmaqtugha,2)
diff(strs,strLocale) sizeof(strLocale,2)
diff(strs,strLayout) sizeof(strLayout,2)
Expand Down Expand Up @@ -467,6 +537,7 @@ block(strs) # struct COMP_KMXPLUS_STRS {
block(strSet2) 61 00 62 00 63 00 block(x) 00 00 # 'abc'
block(strBase) 62 00 61 00 73 00 65 00 block(x) 00 00 # 'base'
block(strElemBkspFrom2) 65 00 block(x) 00 00 # 'e'
block(strGapReserved) 67 00 61 00 70 00 20 00 28 00 72 00 65 00 73 00 65 00 72 00 76 00 65 00 64 00 29 00 block(x) 00 00 # 'gap (reserved)'
block(strHmaqtugha) 68 00 6d 00 61 00 71 00 74 00 75 00 67 00 68 00 61 00 block(x) 00 00 # 'hmaqtugha'
#str #10
block(strLocale) 6d 00 74 00 block(x) 00 00 # 'mt'
Expand Down
Loading

0 comments on commit 7d9eca1

Please sign in to comment.