fix(web/engine): better shorthand API management

This commit is contained in:
jahorton 2020-04-17 09:21:45 +07:00
parent 22a54f4c09
commit 80913fa1db
3 changed files with 47 additions and 35 deletions

View file

@ -958,39 +958,47 @@ namespace com.keyman.text {
return behavior;
}
// Publishes the KeyboardInterface's shorthand API names.
// Note that this may need to be called multiple times; a keyboard-processor consumer
// may extend or overwrite some of the callbacks after this method's initial call.
static __publishShorthandAPI() {
// Keyboard callbacks
let prototype = this.prototype;
var exportKBCallback = function(miniName: string, longName: string) {
prototype[miniName] = prototype[longName];
}
exportKBCallback('KSF', 'saveFocus');
exportKBCallback('KBR', 'beepReset');
exportKBCallback('KT', 'insertText');
exportKBCallback('KR', 'registerKeyboard');
exportKBCallback('KRS', 'registerStub');
exportKBCallback('KC', 'context');
exportKBCallback('KN', 'nul');
exportKBCallback('KCM', 'contextMatch');
exportKBCallback('KFCM', 'fullContextMatch');
exportKBCallback('KIK', 'isKeypress');
exportKBCallback('KKM', 'keyMatch');
exportKBCallback('KSM', 'stateMatch');
exportKBCallback('KKI', 'keyInformation');
exportKBCallback('KDM', 'deadkeyMatch');
exportKBCallback('KB', 'beep');
exportKBCallback('KA', 'any');
exportKBCallback('KDC', 'deleteContext');
exportKBCallback('KO', 'output');
exportKBCallback('KDO', 'deadkeyOutput');
exportKBCallback('KIO', 'indexOutput');
exportKBCallback('KIFS', 'ifStore');
exportKBCallback('KSETS', 'setStore');
exportKBCallback('KLOAD', 'loadStore');
exportKBCallback('KSAVE', 'saveStore');
}
}
// Keyboard callbacks
(function() {
let prototype = KeyboardInterface.prototype;
var exportKBCallback = function(miniName: string, longName: string) {
prototype[miniName] = prototype[longName];
}
exportKBCallback('KSF', 'saveFocus');
exportKBCallback('KBR', 'beepReset');
exportKBCallback('KT', 'insertText');
exportKBCallback('KR', 'registerKeyboard');
exportKBCallback('KRS', 'registerStub');
exportKBCallback('KC', 'context');
exportKBCallback('KN', 'nul');
exportKBCallback('KCM', 'contextMatch');
exportKBCallback('KFCM', 'fullContextMatch');
exportKBCallback('KIK', 'isKeypress');
exportKBCallback('KKM', 'keyMatch');
exportKBCallback('KSM', 'stateMatch');
exportKBCallback('KKI', 'keyInformation');
exportKBCallback('KDM', 'deadkeyMatch');
exportKBCallback('KB', 'beep');
exportKBCallback('KA', 'any');
exportKBCallback('KDC', 'deleteContext');
exportKBCallback('KO', 'output');
exportKBCallback('KDO', 'deadkeyOutput');
exportKBCallback('KIO', 'indexOutput');
exportKBCallback('KIFS', 'ifStore');
exportKBCallback('KSETS', 'setStore');
exportKBCallback('KLOAD', 'loadStore');
exportKBCallback('KSAVE', 'saveStore');
}());
(function() {
// This will be the only call within the keyboard-processor module.
KeyboardInterface.__publishShorthandAPI();
}());
}

View file

@ -12,8 +12,7 @@ global.keyman = {}; // So that keyboard-based checks against the global `keyman`
// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
// Test the top-level LMLayer interface.
// Note: these tests can only be run after BOTH stages of compilation are completed.
// Test the KeyboardProcessor interface.
describe('KeyboardProcessor', function() {
describe('[[constructor]]', function () {
it('should initialize without errors', function () {

View file

@ -20,4 +20,9 @@
publishAPI("_GetAbsoluteY", "getAbsoluteY");
publishAPI("_GetAbsolute", "getAbsolute");
publishAPI("toNzString", "nzString");
}());
(function() {
// DOM-aware KeymanWeb overwrites some of the API functions.
com.keyman.text.KeyboardInterface.__publishShorthandAPI();
}());