diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-token.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-token.ts index 198503d363..de715522e6 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-token.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-token.ts @@ -1,3 +1,11 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + * + * Created by jahorton on 2025-07-30 + * + * Represents cached data about one token (either a word or a unit of whitespace) + * in the context and associated correction-search progress and results. + */ import { buildMergedTransform } from "@keymanapp/models-templates"; import { SearchSpace } from "./distance-modeler.js"; import { KMWString } from "@keymanapp/web-utils"; @@ -19,26 +27,11 @@ import Transform = LexicalModelTypes.Transform; * @param transformId * @returns */ -function textToCharTransforms(text: string, transformId?: number) { - let perCharTransforms: Transform[] = []; - - for(let i=0; i < KMWString.length(text); i++) { - let char = KMWString.charAt(text, i); // is SMP-aware - - let transform: Transform = { - insert: char, - deleteLeft: 0 - }; - - if(transformId) { - transform.id = transformId - } - - perCharTransforms.push(transform); - } - - return perCharTransforms; -} +function textToCharTransforms(text: string, transformId?: number): Transform[] { + return transformId ? + [...text].map(insert => ({insert, deleteLeft: 0, id: transformId})) : + [...text].map(insert => ({insert, deleteLeft: 0})); +} /** * Represents cached data about one token (either a word or a unit of whitespace)