refactor(common/core/web): relocates empty-row fix to keyboard-processor module

This commit is contained in:
jahorton 2021-07-29 09:41:34 +07:00
parent cb4b790a16
commit ed490fcbef
2 changed files with 30 additions and 16 deletions

View file

@ -635,6 +635,35 @@ namespace com.keyman.keyboards {
return this.layerMap[layerId];
}
/**
* Refer to https://github.com/keymanapp/keyman/issues/254, which mentions
* KD-11 from a prior issue-tracking system from the closed-source days that
* resulted in an unintended extra empty row.
*
* It'll be pretty rare to see a keyboard affected by the bug, but we don't
* 100% control all keyboards out there, so it's best we make sure the edge
* case is covered.
*
* @param layers The layer group to be loaded for the form factor. Will be
* mutated by this operation.
*/
static correctLayerEmptyRowBug(layers: LayoutLayer[]) {
for(let n=0; n<layers.length; n++) {
let layer=layers[n];
let rows=layer['row'];
let i: number;
for(i=rows.length; i>0; i--) {
if(rows[i-1]['key'].length > 0) {
break;
}
}
if(i < rows.length) {
rows.splice(i-rows.length,rows.length-i);
}
}
}
/**
*
* @param layout
@ -651,6 +680,7 @@ namespace com.keyman.keyboards {
let layerMap: {[layerId: string]: ActiveLayer} = {};
var rows: LayoutRow[];
ActiveLayout.correctLayerEmptyRowBug(layout['layer']);
layers=layout['layer'];
// ***Delete any empty rows at the end added by compiler bug...

View file

@ -40,22 +40,6 @@ namespace com.keyman.osk {
var tKey=vkbd.getDefaultKeyObject();
tKey['fontsize']=ls.fontSize;
// ***Delete any empty rows at the end added by compiler bug...
for(n=0; n<layers.length; n++) {
let layer=layers[n];
let rows=layer['row'];
for(i=rows.length; i>0; i--) {
if(rows[i-1]['key'].length > 0) {
break;
}
}
if(i < rows.length) {
rows.splice(i-rows.length,rows.length-i);
}
}
// ...remove to here when compiler bug fixed ***
// Set the OSK row height, **assuming all layers have the same number of rows**
// Get the actual available document width and scale factor according to device type