Sg2.9
textarea.range.paragraphs[p]....
Recent RSS
textarea.range.paragraphs[p].words[w] bug
Date:  2. May 2006, 00:50

Here's some code to demonstrate a bug in the text ranges when it comes to words within paragraphs. First create a textarea, select it and execute the following code. You can see by the way it sets the fonts and also what is printed to the console.
It seems to get completely mixed up with the ranges.. I'm guessing it has something to do with the carriage returns..?

I'm getting along now by getting the content of the paragraph, .split(" ")'ing it and then getting the subranges based on the lengths of the strings in the array. But it would be nice if this could be fixed..

textbox=activeDocument.selectedItems[0];
textbox.range.content+="rebel comes out in public in Nepalr"
textbox.range.content+="Moneycontrol.com, India r"
textbox.range.content+=" r"
textbox.range.content+="Activists press Nepal's parliament on new constitutionr"
textbox.range.content+="Irish Examiner, Irelandr"
textbox.range.content+=" r"
textbox.range.content+="6:57 am: Nepal's Parliament reconvenes; cease-fire proposedr"
textbox.range.content+="Santa Fe New Mexican, NMr"

var thefonts=new Array("Times","Courier","Verdana");
var choice=0;
print("the number of paragraphs=" + textbox.range.paragraphs.length)
for(var p=0; p<textbox.range.paragraphs.length; p++){
	for(var w=0; w<textbox.range.paragraphs[p].words.length; w++){
		print(textbox.range.paragraphs[p].words[w].content)
		choice++;
		if(choice==thefonts.length) choice=0;
		textbox.range.paragraphs[p].words[w].characterStyle.font=fonts[thefonts[choice]]
		}
}

Cheers!

Re: textarea.range.paragraphs[p].words[w] bug
Date:  2. May 2006, 00:57

It is indeed a problem with words in paragraphs. When I change the script to go through textbox.range.words[w], it works as it should:

textbox=activeDocument.selectedItems[0];
textbox.range.content+="rebel comes out in public in Nepalr"
textbox.range.content+="Moneycontrol.com, India r"
textbox.range.content+=" r"
textbox.range.content+="Activists press Nepal's parliament on new constitutionr"
textbox.range.content+="Irish Examiner, Irelandr"
textbox.range.content+=" r"
textbox.range.content+="6:57 am: Nepal's Parliament reconvenes; cease-fire proposedr"
textbox.range.content+="Santa Fe New Mexican, NMr"

var thefonts=new Array("Times","Courier","Verdana");
var choice=0;
print("the number of paragraphs=" + textbox.range.paragraphs.length)
for(var w=0; w<textbox.range.words.length; w++){
	print(textbox.range.words[w].content)
	choice++;
	if(choice==thefonts.length) choice=0;
		textbox.range.words[w].characterStyle.font=fonts[thefonts[choice]]
}
Re: textarea.range.paragraphs[p].words[w] bug
From:  Jürg Lehni
Date:  2. October 2006, 14:23

Finally fixed in 2.0.019

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Stroke <-> Fill 09.01.08