mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 01:15:33 +00:00
Relates to #5853. Two things happened here: 1. Construction of Mocks made an assumption that the selection should always be deleted (outputTarget.ts:363). However, for NewContext and PostKeystroke processes, we don't want to change anything. 2. Even if nothing is changed, the transcription would emit what is in theory a no-op ruleTransform (insert="", deleteLeft=0, deleteRight=0). But apps would treat this as deleting the selection. This fix goes a little broader than I would have preferred, but adds a readonly mode to the transcription and mock model, so that we can control explicitly when changes are applied to the text store.
47 lines
No EOL
2 KiB
TypeScript
47 lines
No EOL
2 KiB
TypeScript
namespace com.keyman.dom {
|
|
text.prediction.LanguageProcessor.prototype.canEnable = function(): boolean {
|
|
let keyman = com.keyman.singleton;
|
|
|
|
if(keyman.util.getIEVersion() == 10) {
|
|
console.warn("KeymanWeb cannot properly initialize its WebWorker in this version of IE.");
|
|
return false;
|
|
} else if(keyman.util.getIEVersion() < 10) {
|
|
console.warn("WebWorkers are not supported in this version of IE.");
|
|
return false;
|
|
} else if(typeof Worker != 'function') {
|
|
console.warn("WebWorkers are not supported by this browser.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
let headlessRuleBehaviorFinalize = text.RuleBehavior.prototype.finalize;
|
|
text.RuleBehavior.prototype.finalize = function(this: text.RuleBehavior, processor: text.KeyboardProcessor, outputTarget: text.OutputTarget, readonly: boolean) {
|
|
let keyman = com.keyman.singleton;
|
|
// Execute the standard baseline stuff first.
|
|
headlessRuleBehaviorFinalize.call(this, processor);
|
|
|
|
// newContext and postKeystroke events cannot emit content
|
|
if(readonly) {
|
|
return;
|
|
}
|
|
|
|
// If the transform isn't empty, we've changed text - which should produce a 'changed' event in the DOM.
|
|
let ruleTransform = this.transcription.transform;
|
|
if(ruleTransform.insert != "" || ruleTransform.deleteLeft > 0 || ruleTransform.deleteRight > 0) {
|
|
if(outputTarget instanceof targets.OutputTarget && outputTarget.getElement() == keyman.domManager.activeElement) {
|
|
dom.DOMEventHandlers.states.changed = true;
|
|
}
|
|
}
|
|
|
|
// KMEA and KMEI (embedded mode) use direct insertion of the character string
|
|
if(keyman.isEmbedded) {
|
|
// A special embedded callback used to setup direct callbacks to app-native code.
|
|
keyman['oninserttext'](ruleTransform.deleteLeft, ruleTransform.insert, ruleTransform.deleteRight);
|
|
if(outputTarget instanceof targets.OutputTarget) {
|
|
keyman.refreshElementContent(outputTarget.getElement());
|
|
}
|
|
}
|
|
}
|
|
} |