diff --git a/common/models/templates/src/trie-model.ts b/common/models/templates/src/trie-model.ts index 338d906894..9de2fb9050 100644 --- a/common/models/templates/src/trie-model.ts +++ b/common/models/templates/src/trie-model.ts @@ -454,8 +454,8 @@ class Trie { * @param prefix */ lookup(prefix: string): TextWithProbability[] { - let searchKey = this.toKey(prefix); - let rootTraversal = this.traverseFromRoot().child(searchKey); + const searchKey = this.toKey(prefix); + const rootTraversal = this.traverseFromRoot().child(searchKey); if(!rootTraversal) { return []; @@ -464,14 +464,14 @@ class Trie { const directEntries = rootTraversal.entries; // `Set` requires Chrome 38+, which is more recent than Chrome 35. const directSet: Record = {}; - for(let entry of directEntries) { + for(const entry of directEntries) { directSet[entry.text] = entry.text; } const bestEntries = getSortedResults(rootTraversal); - const deduplicated = bestEntries.filter((entry) => !directSet[entry.text]) + const deduplicated = bestEntries.filter((entry) => !directSet[entry.text]); - // Any entries directly hosted on the current note should get full display + // Any entries directly hosted on the current node should get full display // priority over anything from its descendants. return directEntries.concat(deduplicated); } diff --git a/common/web/lm-worker/src/main/model-compositor.ts b/common/web/lm-worker/src/main/model-compositor.ts index 40517f0bd7..6d2ae258b0 100644 --- a/common/web/lm-worker/src/main/model-compositor.ts +++ b/common/web/lm-worker/src/main/model-compositor.ts @@ -164,10 +164,9 @@ export default class ModelCompositor { let prefixTransform: Transform; let postContextState: correction.TrackedContextState = null; - let currentCasing: CasingForm = null; - if(lexicalModel.languageUsesCasing) { - currentCasing = this.detectCurrentCasing(postContext); - } + const currentCasing: CasingForm = lexicalModel.languageUsesCasing + ? this.detectCurrentCasing(postContext) + : null; // Section 1: determining 'prediction roots'. if(!this.contextTracker) { @@ -428,14 +427,22 @@ export default class ModelCompositor { // prioritize such a suggestion over suggestions that are not. if(keyed(tuple.correction.sample) == keyedPrefix) { if(predictedWord == truePrefix) { + // Exact match: it's a perfect 'keep' suggestion. tuple.matchLevel = SuggestionSimilarity.exact; keepOption = this.toAnnotatedSuggestion(tuple.prediction.sample, 'keep', models.QuoteBehavior.noQuotes); + + // Indicates that this suggestion exists directly within the lexical + // model as a valid suggestion. (We actively display it if it's an + // exact match, but hide it if not, only preserving it for reversions + // if/when needed.) keepOption.matchesModel = true; Object.assign(tuple.prediction.sample, keepOption); keepOption = tuple.prediction.sample as Outcome; } else if(keyCased(predictedWord) == lowercasedPrefix) { + // Case-insensitive match. No diacritic differences; the ONLY difference is casing. tuple.matchLevel = SuggestionSimilarity.sameText; } else if(keyed(predictedWord) == keyedPrefix) { + // Diacritic-insensitive / exact-key match. tuple.matchLevel = SuggestionSimilarity.sameKey; } } @@ -581,7 +588,7 @@ export default class ModelCompositor { } private predictionAutoSelect(suggestionDistribution: CorrectionPredictionTuple[]) { - if(suggestionDistribution.length < 1) { + if(suggestionDistribution.length == 0) { return; }