Skip to main content
Robert at ID-Tasker
Brainiac
February 2, 2023
Question

TextStyleRange bug ? CC 2023 v18

  • February 2, 2023
  • 6 replies
  • 2062 views

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 has been closed for replies.

6 replies

Community Expert
February 2, 2023

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 )

Robert at ID-Tasker
Brainiac
February 2, 2023

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

 

Pretty sure Drop Caps and Nested Styles behave the same.

 

m1b
Community Expert
February 2, 2023

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. 🙂

Robert at ID-Tasker
Brainiac
February 2, 2023

Probably 😉 noted 😉 

 

Community Expert
February 2, 2023

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.

rob day
Community Expert
February 2, 2023

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

Community Expert
February 2, 2023

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.

rob day
Community Expert
February 2, 2023

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]

 

 

Robert at ID-Tasker
Brainiac
February 2, 2023

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.

 

rob day
Community Expert
February 2, 2023

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.

 

 

Robert at ID-Tasker
Brainiac
February 2, 2023

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. 

 

Community Expert
February 2, 2023

> 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.

Robert at ID-Tasker
Brainiac
February 2, 2023

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

 

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