• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

TextStyleRange bug ? CC 2023 v18

Community Expert ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

Lets say we have some text:

 

RobertTkaczyk_0-1675302228169.png

 

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:

 

RobertTkaczyk_1-1675303006664.png

 

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.

 

TOPICS
Bug , Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

 

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

 

Screen Shot 15.png

 

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.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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?

 

Screen Shot 16.png

 

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]

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Also, I’m checking in ID 16.4, so this isn’t new.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Please check tr[0].

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

This might be a work around:

 

 

 

var s = app.activeDocument.selection[0]
var tr = s.textStyleRanges;
var ls = s.characters[-1];
var lr = tr[-1].characters[0]

$.writeln(tr[0].contents) //returns ples
$.writeln(tr[-1].characters.itemByRange(lr,ls).contents) //returns Lemo

 

 

 

Screen Shot 16.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Exactly 🙂 

 

So the bug is confirmed 😞

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Hi,

 

To summarize, a TextStyleRange is not what we thought it was 😞

 

Given a single Text object that I'll suppose having a consistent style, the associated text style range is left-bounded (it won't go before the first targeted character) but it runs as far as needed on the right:

 

MarcAutret_0-1675384360690.png

 

And it only ends when something (explicitly) changes in text styling, so it can even cross the paragraphs:

 

MarcAutret_1-1675384522619.png

 

Whether it is a “bug” or a strangely asymmetrical definition, I don't know, but that's the way InDesign text style ranges are formed and reported at the DOM level.

 

There are cases where (1) we want to get the missing part (to the left) as stressed by @Robert at ID-Tasker, in order to retrieve a maximal, consistent range (no matter the input Text). There are also cases where (2) we do not want the range to expand (to the right) beyond the input Text.

 

Case (2) is easier to manage, since we know the actual length of the input (myText.length or mySel.texts[0].length). In case (1) some extra steps are required to identify the actual beginning of the range (based on parent word, line, paragraph, column, frame, story—relative to the Text under consideration.)

 

Best,

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

But when you get parent Paragraph - it is always returned correctly - so in case of parent TSR - it's a bug 😞

 

It should always return parent in full - selection shouldn't matter in any way. 

 

TSR is a range of text with exactly the same formatting - no confusion here - at least not for me? So it shouldn't be "bounded" to any side nor should "expand" or "contract" - it should be returned in full - like any other "parent".

 

When you need a reference to a parent Spread - would it be OK to get partial reference - left or right page - depending on which side, source object is placed - instead of the Spread?

I know there is no direct reference to a parent Spread - you need to get parent Page and then parent Spread of this Page - so technically, it's a bit pointless example 😉 but I hope you get my point 😉 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

LATEST

I totally agree with you, Robert. The fact is just that TSR haven't been designed as “parent” components. When processed from an arbitrary selection they behave as left-bounded runs, and that's obviously an issue.

 

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Probably 😉 noted 😉 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Hi together,

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

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

 

Test document attached:

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

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

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

 

Pretty sure Drop Caps and Nested Styles behave the same.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

That's an interesting little gotcha! Would be ideal if length was 3 in both cases. Thanks for info.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

but while we are at textStyleRanges

 

And the Style in textStyleRanges doesn’t refer to paragraph or character styles, any change to a character property starts a new range:

 

Screen Shot 20.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2023 Feb 02, 2023

Copy link to clipboard

Copied

Yes, ANY kind of formatting that is different to a surrounding area - will create new TSR - that's the point of TSRs 😉

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines