Merge pull request #6100 from keymanapp/fix/web/execute-popup-layer

fix(web): Use regex to determine display layer and functional layers
This commit is contained in:
Darcy Wong 2022-01-18 11:17:21 +07:00 committed by GitHub
commit 87c18b2434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -248,7 +248,8 @@
var keyPos = x.toString() + ',' + y.toString();
for(i=0; i<obj.length; i++)
{
s=s+obj[i].layer+'-'+obj[i].coreID;
// elementID contains the layer and coreID
s=s+obj[i].elementID;
if(obj[i].sp == 1 || obj[i].sp == 2) shift = true;
if(typeof(obj[i].text) != 'undefined' && obj[i].text != null && obj[i].text != '') s=s+':'+toHex(obj[i].text);
if(i < (obj.length -1)) s=s+';'

View file

@ -349,7 +349,8 @@ namespace com.keyman.text {
/**
* Accept an external key ID (from KeymanTouch) and pass to the keyboard mapping
*
* @param {string} keyName key identifier
* @param {string} keyName key identifier which could contain a display layer and a "functional" layer
* e.g: 'shift-K_E+rightalt-shift'
**/
keymanweb['executePopupKey'] = function(keyName: string) {
let osk = keymanweb.osk;
@ -361,16 +362,21 @@ namespace com.keyman.text {
/* Clear any pending (non-popup) key */
osk.vkbd.keyPending = null;
// Changes for Build 353 to resolve KMEI popup key issues
// Changes for Build 353 to resolve KMEI popup key issues
keyName=keyName.replace('popup-',''); //remove popup prefix if present (unlikely)
// Regex for 'display layer'-'virtual key name'+'optional functional layer'
// Can't just split on '-' because some layers like ctrl-shift contain it.
let separatorIndex = keyName.lastIndexOf('-');
if (separatorIndex > 0) {
keyName = keyName.substring(separatorIndex+1);
// Virtual key name starts with T_, K_, or U_
// matches[1]: displayLayer (not used)
// matches[2]: keyId
// matches[3]: optional functionalLayer
let matches = keyName.match(/^(.+)-([TKU]_[^+]+)\+?(.+)?$/);
if (matches == null) {
return false;
}
keyName = matches[2] + (matches[3] ? '+' + matches[3] : '');
// Note: this assumes Lelem is properly attached and has an element interface.
// Currently true in the Android and iOS apps.
var Lelem=keymanweb.domManager.lastActiveElement;