diff --git a/core/src/kmx/kmx_plus.cpp b/core/src/kmx/kmx_plus.cpp index 0bffc595a9..b1ded8744d 100644 --- a/core/src/kmx/kmx_plus.cpp +++ b/core/src/kmx/kmx_plus.cpp @@ -668,9 +668,9 @@ COMP_KMXPLUS_KEY2_Helper::getKeys(KMX_DWORD i) const { return keys + i; } -const COMP_KMXPLUS_KEY2_KEY * -COMP_KMXPLUS_KEY2_Helper::findKey(KMX_DWORD strId) const { - for (KMX_DWORD i = 0; i < key2->keyCount; i++) { +const COMP_KMXPLUS_KEY2_KEY* +COMP_KMXPLUS_KEY2_Helper::findKeyByStringId(KMX_DWORD strId, KMX_DWORD &i) const { + for (i = 0; i < key2->keyCount; i++) { if (keys[i].id == strId) { return &keys[i]; } diff --git a/core/src/kmx/kmx_plus.h b/core/src/kmx/kmx_plus.h index 45b603e7a0..3007138bd4 100644 --- a/core/src/kmx/kmx_plus.h +++ b/core/src/kmx/kmx_plus.h @@ -503,7 +503,13 @@ public: const COMP_KMXPLUS_KEY2_FLICK_ELEMENT *getFlickElements(KMX_DWORD element) const; const COMP_KMXPLUS_KEY2_KMAP *getKmap(KMX_DWORD element) const; - const COMP_KMXPLUS_KEY2_KEY *findKey(KMX_DWORD strId) const; + /** + * Search for a key by string id. + * @param strID id to search for + * @param index on exit, index of item if found. Undefined otherwise. + * @return pointer to key or nullptr + */ + const COMP_KMXPLUS_KEY2_KEY *findKeyByStringId(KMX_DWORD strId, KMX_DWORD &index) const; private: const COMP_KMXPLUS_KEY2 *key2; diff --git a/core/tests/unit/ldml/ldml_test_source.cpp b/core/tests/unit/ldml/ldml_test_source.cpp index 6ea4b0a83d..12344b0177 100644 --- a/core/tests/unit/ldml/ldml_test_source.cpp +++ b/core/tests/unit/ldml/ldml_test_source.cpp @@ -405,15 +405,25 @@ void LdmlJsonTestSource::set_key_from_id(key_event& k, const std::u16string& id) } // OK. Now we can search the keybag - auto *key2 = kmxplus->key2Helper.findKey(strId); + KMX_DWORD keyIndex = 0; + auto *key2 = kmxplus->key2Helper.findKeyByStringId(strId, keyIndex); assert(key2 != nullptr); if (key2 == nullptr) { k = {0, 0}; return; } - k.vk = key2->vkey; - // TODO: modifier! + // Now, look for the _first_ candidate vkey match in the kmap. + for (KMX_DWORD kmapIndex = 0; kmapIndex < kmxplus->key2->kmapCount; kmapIndex++) { + auto *kmap = kmxplus->key2Helper.getKmap(kmapIndex); + assert(kmap != nullptr); + if (kmap->key == keyIndex) { + k = {(km_kbp_virtual_key)kmap->vkey, (uint16_t)kmap->mod}; + return; + } + } + // Else, unfound + return; }