From 1d0e930485c2b6905c8cb0b24c68a394228856c9 Mon Sep 17 00:00:00 2001 From: jahorton Date: Tue, 24 Mar 2020 08:51:29 +0700 Subject: [PATCH 1/2] refactor(web/engine): relocates keyboard tag code, adds typing --- web/source/keyboards/keyboard.ts | 29 +++++++++++++++++++++++++--- web/source/keyboards/kmwkeyboards.ts | 5 ----- web/source/text/kbdInterface.ts | 9 ++++----- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/web/source/keyboards/keyboard.ts b/web/source/keyboards/keyboard.ts index 24d1b6ac3a..e41d8b0353 100644 --- a/web/source/keyboards/keyboard.ts +++ b/web/source/keyboards/keyboard.ts @@ -1,4 +1,15 @@ namespace com.keyman.keyboards { + /** + * Stores preprocessed properties of a keyboard for quick retrieval later. + */ + class CacheTag { + stores: {[storeName: string]: text.ComplexKeyboardStore}; + + constructor() { + this.stores = {}; + } + } + /** * Acts as a wrapper class for Keyman keyboards compiled to JS, providing type information * and keyboard-centered functionality in an object-oriented way without modifying the @@ -132,6 +143,21 @@ namespace com.keyman.keyboards { } } + private get cacheTag(): CacheTag { + let tag = this.scriptObject['_kmw']; + + if(!tag) { + tag = new CacheTag(); + this.scriptObject['_kmw'] = tag; + } + + return tag; + } + + get explodedStores(): {[storeName: string]: text.ComplexKeyboardStore} { + return this.cacheTag.stores; + } + usesDesktopLayoutOnDevice(device: Device) { if(this.scriptObject['KVKL']) { // A custom mobile layout is defined... but are we using it? @@ -153,8 +179,5 @@ namespace com.keyman.keyboards { this.scriptObject['KNS'](_PCommand, _PTarget, _PData); } } - - // TODO: Provide public property-retrieving methods on this class, rather than as part of - // the KeyboardManager object. } } \ No newline at end of file diff --git a/web/source/keyboards/kmwkeyboards.ts b/web/source/keyboards/kmwkeyboards.ts index 4170a21a5a..051cdd940c 100644 --- a/web/source/keyboards/kmwkeyboards.ts +++ b/web/source/keyboards/kmwkeyboards.ts @@ -114,11 +114,6 @@ namespace com.keyman.keyboards { return textProcessor.activeKeyboard ? textProcessor.activeKeyboard.id : ''; } - getActiveKeyboardTag(): KeyboardTag { - let textProcessor = com.keyman.singleton.textProcessor; - return textProcessor.activeKeyboard ? textProcessor.activeKeyboard.scriptObject['_kmw'] : null; - } - getActiveLanguage(fullName?: boolean): string { if(this.activeStub == null) { return ''; diff --git a/web/source/text/kbdInterface.ts b/web/source/text/kbdInterface.ts index 89bbe1bfcb..fcea1d26d4 100644 --- a/web/source/text/kbdInterface.ts +++ b/web/source/text/kbdInterface.ts @@ -626,12 +626,11 @@ namespace com.keyman.text { _ExplodeStore(store: KeyboardStore): ComplexKeyboardStore { if(typeof(store) == 'string') { - let keyman = com.keyman.singleton; - var kbdTag = keyman.keyboardManager.getActiveKeyboardTag(); + let cachedStores = this.activeKeyboard.explodedStores; // Is the result cached? - if(kbdTag.stores[store]) { - return kbdTag.stores[store]; + if(cachedStores[store]) { + return cachedStores[store]; } // Nope, so let's build its cache. @@ -641,7 +640,7 @@ namespace com.keyman.text { } // Cache the result for later! - kbdTag.stores[store] = result; + cachedStores[store] = result; return result; } else { return store; From b9932f24e3871d0ad2c55150ccb04c7ccc7e64c3 Mon Sep 17 00:00:00 2001 From: jahorton Date: Tue, 24 Mar 2020 12:49:32 +0700 Subject: [PATCH 2/2] fix(web/engine): Ensures KeyboardInterface available for unit tests --- web/source/text/processor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/source/text/processor.ts b/web/source/text/processor.ts index dc1902838e..e0e7dd63ec 100644 --- a/web/source/text/processor.ts +++ b/web/source/text/processor.ts @@ -71,6 +71,10 @@ namespace com.keyman.text { // All old deadkeys and keyboard-specific cache should immediately be invalidated // on a keyboard change. this.keyboardInterface.resetContext(); + + // Ensure that the setting propagates immediately to the keyboard interface object. + // Matters for some unit tests. + this.keyboardInterface.activeKeyboard = keyboard; } /**