Illustrator and scripting inconsistent words[] when tabs used
Can someone explain the results when the following is run on an Illustrator document with one text frame?
var myDoc = app.activeDocument;
var myTextFrame = myDoc.textFrames[0]
myTextFrame.contents = "Lorem ipsum dolor sit amet\rLorem\tipsum\tdolor\tsit\tamet";
alert(myTextFrame.words.length);
alert(myTextFrame.lines[0].words.length);
alert(myTextFrame.lines[1].words.length);
for (l=0; l<2; l++)
{
concat = "#";
for (i=0; i<myTextFrame.lines[l].words.length; i++)
{
concat += myTextFrame.lines[l].words[i].contents;
concat += "#";
}
alert(concat);
}
14
5
9
"#Lorem#ipsum#dolor#sit#amet#"
"#Lorem#Lorem#ipsum#ipsum#dolor#dolor#sit#sit#amet#"
Why does separating the words by tabs seem to duplicate all but the last word in the line?
Is this a bug, and if not, what is the logic behind it?
Running on Windows 11 and I believe I have the latest version of Illustrator as downloaded via CC
-
Sergey Osokin
commented
The tab character isn't considered the same separator as a space (\s). Adobe's textFrame.words collection is very unreliable. For example, two words with a dot and no space, "lorem.ipsum," are considered one word by the parser. You have to create your own word parser for textFrame, taking into account the possible separator characters.