diff --git a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts index 21838f564a..3b74fccbdc 100644 --- a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts +++ b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts @@ -46,12 +46,13 @@ namespace wordBreakers { let current: Span | undefined = results[index]; let window = []; - if (previous && previous.end === current.start) { + if (previous && spansAreBackToBack(previous, current)) { window.push(index - 1); } + window.push(index); - if (next && current.end === next.start) { + if (next && spansAreBackToBack(current, next)) { window.push(index + 1); } @@ -92,6 +93,14 @@ namespace wordBreakers { return contiguousRanges; } + /** + * Returns true when the spans are contiguous. + * Order matters when calling this function! + */ + function spansAreBackToBack(former: Span, latter: Span): boolean { + return former.end === latter.start; + } + /** * Given an array of ranges of indices, and the corresponding spans, * concatenates spans according to the ranges of indices.