chore(web): incorporate suggestions, address concerns from PR review

This commit is contained in:
Joshua A. Horton 2024-07-08 10:43:40 +07:00
parent 067d033d0d
commit 946ec38ad4
2 changed files with 17 additions and 10 deletions

View file

@ -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<string, string> = {};
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);
}

View file

@ -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<Keep>;
} 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;
}