Skip to main content
Robert at ID-Tasker
Legend
Feb 2, 2023 2:08 AM UTC
Question

TextStyleRange bug ? CC 2023 v18

Lets say we have some text:

 

 

and there are some different formattings - doesn't matter if local or CharStyles.

Now, lets iterate through TextStyleRanges collection of the SELECTED text.

 

Above example have 4x TSRs:

 

 

2nd and 3rd TSRs can be correctly referenced & compared (I'm checking indexes of 1st and last characters) but for simplification:

 

myText = myText.TextStyleRanges.Item(1).Texts.Item(1)

 

BUT - returned parent TSR for the 1st text - "NeYxEcTÓW"- even when I've not selected whole TSR - is the same as myText - in this case, parent TSR should be the same as the whole paragraph - "lOmY PfDiIcŁ KoNeYxEcTÓW" - so in the screen above it should be "Text" instead of "TSR" in the TYPE column.

 

parent of the 4th TSR is returned correctly as "kxlinnacipm" and I have "Text" in the TYPE column.

 

 

Can someone verify if you have the same problem - that parent TSR is returned correctly when you select "start" of the TSR - but incorrectly when you select "end" of the TSR.

 

Parent Paragraph - myText.Paragraphs.Item(1).Texts.Item(1) - doesn't have this problem.

 

This topic is closed to new replies. Start a new post to keep the conversation going.

23 replies

Community Expert
Feb 2, 2023 8:35 PM UTC

Hi together,

it's a bit off topic perhaps, but while we are at textStyleRanges now consider the following:

 

Test document attached:

TextStyleRanges-length-GREP-Style-vs-CharacterStyleApplied-2023.indd

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
Robert at ID-Tasker
Legend
Feb 2, 2023 8:54 PM UTC

Because formatting applied through a GREP Style is kind of "virtual" 😞

 

Pretty sure Drop Caps and Nested Styles behave the same.

 

Translate
m1b
Community Expert
Community Expert
Feb 2, 2023 8:03 PM UTC

Thanks @Robert at ID-Tasker for looking into this. I strongly suggest next time deliberately using a *very* simple and clean example, like @rob day's Apple and Lemons example. Your example was difficult to parse and might have confused some of us. 🙂

Translate
Robert at ID-Tasker
Legend
Feb 2, 2023 8:07 PM UTC

Probably 😉 noted 😉 

 

Translate
Peter Kahrel
Community Expert
Community Expert
Feb 2, 2023 7:30 PM UTC

> At first I thought the same, but tr[-1] returns [object TextStyleRange] not [object Text], so its contents would be the text to the end of the style range—no?

 

Still, tr[0] returns [object TextStyleRange] and its contents returns ples. So that's not consistent.

Translate
rob day
Community Expert
Community Expert
Feb 2, 2023 7:37 PM UTC

Just checked in CS6 and it the same, so it’s been that way for awhile

Translate
Peter Kahrel
Community Expert
Community Expert
Feb 2, 2023 7:04 PM UTC

Robert is right that not all is well: when you select "ples" to "lem" in Rob's example, then

app.selection[0].textStyleRanges[-1].contents

returns lemons, it should return lem.

app.selection[0].textStyleRanges[0].contents

 returns ples, which is correct.

Translate
rob day
Community Expert
Community Expert
Feb 2, 2023 7:15 PM UTC

returns lemons, it should return lem.

 

At first I thought the same, but tr[-1] returns [object TextStyleRange] not [object Text], so its contents would be the text to the end of the style range—no?

 

 

var s = app.activeDocument.selection[0]
var tr = s.textStyleRanges;

$.writeln(tr.length) //returns 7
$.writeln(tr[0].contents) //returns ples
$.writeln(tr[1].contents) //returns ,
$.writeln(tr[-1]) //returns [object TextStyleRange]
$.writeln(tr[-1].contents) //returns Lemons
$.writeln(tr[0].parent.contents) //returns Otatem ium cuscieni ut fugiam et etur? Apples, Oranges, Limes, Lemons—Pidunditibus mos dus modit fugiatquosam.
$.writeln(tr[0].paragraphs[0]) // returns [object Paragraph]

 

 

Translate
Robert at ID-Tasker
Legend
Feb 2, 2023 7:47 PM UTC

Yes, and that's correct for tr[-1] - but the problem is with tr[0] - it returns only part of the TSR - the rest/selection - when it should also return what is before the selection.

 

Translate
rob day
Community Expert
Community Expert
Feb 2, 2023 5:09 PM UTC

Hi @Robert at ID-Tasker , Did you double check the textStyleRange length to make sure it really is 4? With this example:

 

 

I get this with JS:

 

 

var s = app.activeDocument.selection[0]
var tr = s.textStyleRanges;

$.writeln(tr.length) //returns 7
$.writeln(tr[0].contents) //returns Apples
$.writeln(tr[1].contents) //returns ,
$.writeln(tr[-1].contents) //returns Lemons
$.writeln(tr[0].parent.contents) //returns Otatem ium cuscieni ut fugiam et etur? Apples, Oranges, Limes, Lemons—Pidunditibus mos dus modit fugiatquosam.

 

 

Translate
Robert at ID-Tasker
Legend
Feb 2, 2023 5:35 PM UTC

It works fine when you select WHOLE TSR - try to select from "ples" to "lemo".

 

And Parent for TR[0] is Story - no problem there. 

 

Translate
Peter Kahrel
Community Expert
Community Expert
Feb 2, 2023 2:45 PM UTC

> myText.Paragraphs.Item(1).Texts.Item(1)

This should return the first text-style range as a text object. In JS it works like that just as in VBS, and I think that that's correct.

Translate
Robert at ID-Tasker
Legend
Feb 2, 2023 5:33 PM UTC

I'm not talking about Paragraph - I'm talking about TextStyleRanges. 

 

Your quote will return whole Paragraph as a Text object - not a TSR. 

 

Translate