textRange.words counts words wrong in a wrong way
If you try to calculate a number of words and store them for later using textRange.words and a punctuation marks placed one space after the word, as demonstrated in the video, Ai cuts words in wrong places, resulting words being trimmed.
This breaks all scripts that rely on this method.
You have to rename 'words-bug.txt' into 'words-bug.js' and 'words-bug.pdf' to 'words-bug.ai' to test it, since UV does not allow to upload these type formats.
As per the comment, the bug is 'fixed' in 27.4, by creating another bug — https://illustrator.uservoice.com/forums/601447-illustrator-desktop-bugs/suggestions/46537261-incorrect-word-count-via-script
Please check and upvote the problem
-
m1b commented
I have just tested this using AI 27.4 on MacOS 13.3.1 and this bug has been fixed.
However, I think the fix may have created [this new bug](https://illustrator.uservoice.com/forums/601447-illustrator-desktop-bugs/suggestions/46537261-incorrect-word-count-via-script).