Skip to content

Commit 3cf0c79

Browse files
committed
fix(text): fix word split to include separator at the end of words
1 parent f886fff commit 3cf0c79

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

src/shapes.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,11 @@ export class Text extends Shape {
344344
return this.splitInWords();
345345
}
346346

347-
private pushSeparatorInWords(pickedChars: number): [string, number] {
348-
return [this.text[pickedChars], pickedChars + 1]
349-
}
350-
351347
private buildWord(pickedChars: number, word: string): [string, number] {
352-
while (!C.TEXT_SEPARATORS.includes(this.text[pickedChars]) && pickedChars < this.text.length) {
348+
while (pickedChars < this.text.length) {
353349
word += this.text[pickedChars];
354350
pickedChars++;
351+
if (C.TEXT_SEPARATORS.includes(word[word.length - 1])) break;
355352
}
356353
return [word, pickedChars]
357354
}
@@ -361,8 +358,7 @@ export class Text extends Shape {
361358
let pickedChars = 0;
362359
while (pickedChars < this.text.length) {
363360
let word = "";
364-
if (C.TEXT_SEPARATORS.includes(this.text[pickedChars])) [word, pickedChars] = this.pushSeparatorInWords(pickedChars)
365-
else [word, pickedChars] = this.buildWord(pickedChars, word);
361+
[word, pickedChars] = this.buildWord(pickedChars, word);
366362
words.push(word);
367363
}
368364
return words.length > 1 ? words : this.text.split("")

0 commit comments

Comments
 (0)