Skip to content

Commit

Permalink
Merge pull request #11164 from keymanapp/fix/common/models/suggestion…
Browse files Browse the repository at this point in the history
…s-after-multi-whitespace

fix(common/models): suggestion stability after multiple whitespaces
  • Loading branch information
jahorton authored Apr 5, 2024
2 parents d711856 + db9e807 commit eeac2b5
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions common/web/lm-worker/src/main/correction/context-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ export class ContextTracker extends CircularArray<TrackedContextState> {
* - For languages using whitespace to word-break, said keystroke would have to include said whitespace to break the assumption.
*/

function maintainLastToken() {
if(isWhitespace && editPath[tailIndex] == 'match') {
/*
We can land here if there are multiple whitespaces in a row.
There's already an implied whitespace to the left, so we conceptually
merge the new whitespace with that one.
*/
return state;
} else if(isBackspace) {
// Consider backspace entry for this case?
state.replaceTailForBackspace(finalToken, primaryInput.id);
} else {
state.updateTail(primaryInput ? transformDistribution : null, finalToken);
}
}

// If there is/was more than one context token available...
if(editPath.length > 1) {
// We're removing a context token, but at least one remains.
Expand Down Expand Up @@ -438,14 +454,11 @@ export class ContextTracker extends CircularArray<TrackedContextState> {
}

state.pushTail(pushedToken);
} else { // We're editing the final context token.
} else {
// We're editing the final context token.
// TODO: Assumption: we didn't 'miss' any inputs somehow.
// As is, may be prone to fragility should the lm-layer's tracked context 'desync' from its host's.
if(isBackspace) {
state.replaceTailForBackspace(finalToken, primaryInput.id);
} else {
state.updateTail(primaryInput ? transformDistribution : null, finalToken);
}
maintainLastToken();
}
// There is only one word in the context.
} else {
Expand All @@ -458,13 +471,9 @@ export class ContextTracker extends CircularArray<TrackedContextState> {
token.raw = tokenizedContext[0];
token.transformDistributions = [transformDistribution];
state.pushTail(token);
} else { // Edit the lone context token.
// Consider backspace entry for this case?
if(isBackspace) {
state.replaceTailForBackspace(finalToken, primaryInput.id);
} else {
state.updateTail(primaryInput ? transformDistribution : null, finalToken);
}
} else {
// Edit the lone context token.
maintainLastToken();
}
}
return state;
Expand Down

0 comments on commit eeac2b5

Please sign in to comment.