mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-07 22:47:29 +00:00
refactor(web/engine): returns prediction Promise on RuleBehavior
This commit is contained in:
parent
f9a9810ee3
commit
e363542c9e
6 changed files with 20 additions and 13 deletions
|
|
@ -224,7 +224,7 @@ namespace com.keyman.dom {
|
|||
return true;
|
||||
}
|
||||
|
||||
var LeventMatched = !core.processKeyEvent(Levent);
|
||||
var LeventMatched = (core.processKeyEvent(Levent) != null);
|
||||
|
||||
if(LeventMatched) {
|
||||
if(e && e.preventDefault) {
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ namespace com.keyman.text {
|
|||
try {
|
||||
// Now that we've manually constructed a proper keystroke-sourced KeyEvent, pass control
|
||||
// off to the processor for its actual execution.
|
||||
return keyman.core.processKeyEvent(Lkc); // Lack of second argument -> `usingOSK == false`
|
||||
return keyman.core.processKeyEvent(Lkc) != null;
|
||||
} catch (err) {
|
||||
console.error(err.message, err);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace com.keyman.osk {
|
|||
return true;
|
||||
}
|
||||
|
||||
let retVal = keyman.core.processKeyEvent(Lkc);
|
||||
let retVal = (keyman.core.processKeyEvent(Lkc) != null);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace com.keyman.text {
|
|||
*
|
||||
* @param {Object} e The abstracted KeyEvent to use for keystroke processing
|
||||
*/
|
||||
processKeyEvent(keyEvent: KeyEvent): boolean {
|
||||
processKeyEvent(keyEvent: KeyEvent) {
|
||||
let keyman = com.keyman.singleton;
|
||||
let formFactor = keyEvent.device.formFactor;
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ namespace com.keyman.text {
|
|||
// Notify the ModelManager of new input - it's predictive text time!
|
||||
ruleBehavior.transcription.alternates = alternates;
|
||||
// Yes, even for ruleBehavior.triggersDefaultCommand. Those tend to change the context.
|
||||
this.languageProcessor.predict(ruleBehavior.transcription);
|
||||
ruleBehavior.predictionPromise = this.languageProcessor.predict(ruleBehavior.transcription);
|
||||
|
||||
// KMEA and KMEI (embedded mode) use direct insertion of the character string
|
||||
if(keyman.isEmbedded) {
|
||||
|
|
@ -188,7 +188,7 @@ namespace com.keyman.text {
|
|||
// once THOSE are properly relocated. (They're too DOM-heavy to remain in web-core.)
|
||||
|
||||
// Only return true (for the eventual event handler's return value) if we didn't match a rule.
|
||||
return ruleBehavior == null;
|
||||
return ruleBehavior;
|
||||
}
|
||||
|
||||
public resetContext() {
|
||||
|
|
|
|||
|
|
@ -111,9 +111,9 @@ namespace com.keyman.text.prediction {
|
|||
return this.lmEngine.wordbreak(context);
|
||||
}
|
||||
|
||||
public predict(transcription?: Transcription) {
|
||||
public predict(transcription?: Transcription): Promise<Suggestion[]> {
|
||||
if(!this.isActive) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
let keyman = com.keyman.singleton;
|
||||
|
|
@ -121,14 +121,14 @@ namespace com.keyman.text.prediction {
|
|||
// If there's no active model, there can be no predictions.
|
||||
// We'll also be missing important data needed to even properly REQUEST the predictions.
|
||||
if(!this.currentModel || !this.configuration) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// We've already invalidated any suggestions resulting from any previously-existing Promise -
|
||||
// may as well officially invalidate them via event.
|
||||
keyman.util.callEvent(ModelManager.EVENT_PREFIX + "invalidatesuggestions", 'new');
|
||||
|
||||
this.predict_internal(transcription);
|
||||
return this.predict_internal(transcription);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -136,7 +136,7 @@ namespace com.keyman.text.prediction {
|
|||
* have been raised.
|
||||
* @param transcription The triggering transcription (if it exists)
|
||||
*/
|
||||
private predict_internal(transcription?: Transcription) {
|
||||
private predict_internal(transcription?: Transcription): Promise<Suggestion[]> {
|
||||
let keyman = com.keyman.singleton;
|
||||
|
||||
if(!transcription) {
|
||||
|
|
@ -144,7 +144,7 @@ namespace com.keyman.text.prediction {
|
|||
if(t) {
|
||||
transcription = t.buildTranscriptionFrom(t, null);
|
||||
} else {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,12 +155,14 @@ namespace com.keyman.text.prediction {
|
|||
var promise = this.currentPromise = this.lmEngine.predict(transcription.alternates || transcription.transform, context);
|
||||
|
||||
let mm = this;
|
||||
promise.then(function(suggestions: Suggestion[]) {
|
||||
return promise.then(function(suggestions: Suggestion[]) {
|
||||
if(promise == mm.currentPromise) {
|
||||
let result = new ReadySuggestions(suggestions, transform.id);
|
||||
keyman.util.callEvent(ModelManager.EVENT_PREFIX + "suggestionsready", result);
|
||||
mm.currentPromise = null;
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ namespace com.keyman.text {
|
|||
*/
|
||||
warningLog?: string;
|
||||
|
||||
/**
|
||||
* If predictive text is active, contains a Promise returning predictive Suggestions.
|
||||
*/
|
||||
predictionPromise?: Promise<Suggestion[]>;
|
||||
|
||||
finalize(processor: KeyboardProcessor) {
|
||||
let outputTarget = this.transcription.keystroke.Ltarg;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue