Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common/core/web): error from early fat-finger termination due to OS interruptions #5479

Merged
merged 6 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/core/web/input-processor/src/text/inputProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ namespace com.keyman.text {
if(pair.p < KEYSTROKE_EPSILON) {
break;
} else if(timer && timer() >= TIMEOUT_THRESHOLD) {
// Note: it's always possible that the thread _executing_ our JS
// got paused by the OS, even if JS itself is single-threaded.
//
// The case where `alternates` is initialized (line 167) but empty
// (because of net-zero loop iterations) MUST be handled.
break;
}

Expand All @@ -187,6 +192,8 @@ namespace com.keyman.text {

// If alternateBehavior.beep == true, ignore it. It's a disallowed key sequence,
// so we expect users to never intend their use.
//
// Also possible that this set of conditions fail for all evaluated alternates.
if(alternateBehavior && !alternateBehavior.beep && pair.p > 0) {
let transform: Transform = alternateBehavior.transcription.transform;

Expand Down Expand Up @@ -215,7 +222,9 @@ namespace com.keyman.text {
// -- All keystroke (and 'alternate') processing is now complete. Time to finalize everything! --

// Notify the ModelManager of new input - it's predictive text time!
ruleBehavior.transcription.alternates = alternates;
if(alternates && alternates.length > 0) {
ruleBehavior.transcription.alternates = alternates;
}
// Yes, even for ruleBehavior.triggersDefaultCommand. Those tend to change the context.
ruleBehavior.predictionPromise = this.languageProcessor.predict(ruleBehavior.transcription);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,16 @@ namespace com.keyman.text.prediction {
this.lmEngine.resetContext(context);
}

let alternates = transcription.alternates;
if(!alternates || alternates.length == 0) {
alternates = [{
sample: transcription.transform,
p: 1.0
}];
}

let transform = transcription.transform;
var promise = this.currentPromise = this.lmEngine.predict(transcription.alternates || transcription.transform, context);
var promise = this.currentPromise = this.lmEngine.predict(alternates, context);

let lp = this;
return promise.then(function(suggestions: Suggestion[]) {
Expand Down
8 changes: 8 additions & 0 deletions common/predictive-text/worker/model-compositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class ModelCompositor {

if(!(transformDistribution instanceof Array)) {
transformDistribution = [ {sample: transformDistribution, p: 1.0} ];
} else if(transformDistribution.length == 0) {
transformDistribution.push({
jahorton marked this conversation as resolved.
Show resolved Hide resolved
sample: {
insert: '',
deleteLeft: 0
},
p: 1.0
})
mcdurdin marked this conversation as resolved.
Show resolved Hide resolved
}

let inputTransform = transformDistribution.sort(function(a, b) {
Expand Down