Skip to content

Instantly share code, notes, and snippets.

@trych
Last active September 6, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trych/cd4b9bb0f65064ea6f18b4fdba75eec3 to your computer and use it in GitHub Desktop.
Save trych/cd4b9bb0f65064ea6f18b4fdba75eec3 to your computer and use it in GitHub Desktop.
Demonstrates how to retrieve a text object resembling the last text style range *within* a single line.
#target indesign
// use on some text frame with several text style ranges in the first line
// if the text range continues into the second line, only the range within the first line will be returned
var l = app.activeDocument.textFrames.firstItem().lines.firstItem();
var lir = getLastInlineRange(l);
app.select(lir);
function getLastInlineRange(l) {
var ltsr = l.textStyleRanges.lastItem();
return ltsr.lines.length > 1 ? l.parentTextFrames[0].insertionPoints.itemByRange(ltsr.insertionPoints.firstItem().index, l.insertionPoints.lastItem().index) : ltsr;
}
@trych
Copy link
Author

trych commented Sep 6, 2019

Regarding the issues discussed in this Tweet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment