Merge pull request #12906 from keymanapp/change/web/keep-suggestion-transforms

change(web): make 'keep' transform pattern match standard suggestion pattern by including the prefix string
This commit is contained in:
Joshua Horton 2025-01-16 15:49:21 +07:00 committed by GitHub
commit 0cbbcaa52a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View file

@ -558,11 +558,13 @@ export function processSimilarity(
return;
}
// Generate a default 'keep' option if one was not otherwise produced.
// IMPORTANT: duplicate the original transform. Causes nasty side-effects
// for context-tracking otherwise!
let keepTransform: Transform = { ...inputTransform };
// Generate a full-word 'keep' replacement like other suggestions when one is not otherwise
// produced; we want to replace the full token in the same manner used for other suggestions.
const basePrefixLength = truePrefix.kmwLength() - inputTransform.insert.kmwLength() + inputTransform.deleteLeft;
const keepTransform = {
insert: truePrefix,
deleteLeft: basePrefixLength
};
// 1 is a filler value; goes unused b/c is for a 'keep'.
let keepSuggestion = models.transformToSuggestion(keepTransform, 1);

View file

@ -340,8 +340,8 @@ describe('processSimilarity', () => {
prediction: {
sample: {
transform: {
insert: 'e',
deleteLeft: 0
insert: 'iphone',
deleteLeft: 5
},
displayAs: '<iphone>',
matchesModel: false,

View file

@ -932,8 +932,8 @@ describe('ModelCompositor', function() {
assert.equal(suggestions.length, 1);
let expectedTransform = {
insert: ' ', // Keeps current context the same, though it adds a wordbreak.
deleteLeft: 0
insert: 'hi ', // Keeps current context the same, though it adds a wordbreak.
deleteLeft: 2
}
assert.deepEqual(suggestions[0].transform, expectedTransform);
});