mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-24 08:37:42 +00:00
Merge pull request #2883 from keymanapp/refactor/web/engine/keyboardTag
refactor(web/engine): relocates keyboard tag code, adds typing
This commit is contained in:
commit
573f2e8652
4 changed files with 34 additions and 13 deletions
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
|
@ -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 '';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue