fix(web): context-tracker newFlag management for new contexts

This commit is contained in:
Joshua A. Horton 2022-09-05 14:02:55 +07:00
parent b47596a803
commit 26c5150977
2 changed files with 16 additions and 3 deletions

View file

@ -461,7 +461,9 @@ namespace correction {
return state;
}
static modelContextState(tokenizedContext: USVString[], lexicalModel: LexicalModel): TrackedContextState {
static modelContextState(tokenizedContext: USVString[],
transformDistribution: Distribution<Transform>,
lexicalModel: LexicalModel): TrackedContextState {
let baseTokens = tokenizedContext.map(function(entry) {
let token = new TrackedContextToken();
token.raw = entry;
@ -495,6 +497,17 @@ namespace correction {
state.pushTail(token);
}
for(let i = 0; i < state.tokens.length - 1; i++) {
state.tokens[i].newFlag = false;
}
const finalToken = state.tokens[state.tokens.length - 1];
const baseTransform = (transformDistribution && transformDistribution.length > 0) ? transformDistribution[0] : null;
if(!baseTransform || baseTransform.sample.insert != finalToken.raw) {
finalToken.newFlag = false;
}
return state;
}
@ -537,7 +550,7 @@ namespace correction {
//
// Assumption: as a caret needs to move to context before any actual transform distributions occur,
// this state is only reached on caret moves; thus, transformDistribution is actually just a single null transform.
let state = ContextTracker.modelContextState(tokenizedContext.left, model);
let state = ContextTracker.modelContextState(tokenizedContext.left, transformDistribution, model);
state.taggedContext = context;
this.enqueue(state);
return state;

View file

@ -638,7 +638,7 @@ class ModelCompositor {
// than before.
if(this.contextTracker) {
let tokenizedContext = models.tokenize(this.lexicalModel.wordbreaker || wordBreakers.default, context);
let contextState = correction.ContextTracker.modelContextState(tokenizedContext.left, this.lexicalModel);
let contextState = correction.ContextTracker.modelContextState(tokenizedContext.left, null, this.lexicalModel);
this.contextTracker.enqueue(contextState);
}
}