mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-02 13:47:42 +00:00
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:
commit
0cbbcaa52a
3 changed files with 11 additions and 9 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -340,8 +340,8 @@ describe('processSimilarity', () => {
|
|||
prediction: {
|
||||
sample: {
|
||||
transform: {
|
||||
insert: 'e',
|
||||
deleteLeft: 0
|
||||
insert: 'iphone',
|
||||
deleteLeft: 5
|
||||
},
|
||||
displayAs: '<iphone>',
|
||||
matchesModel: false,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue