Skip to main content
dublove
Legend
Oct 26, 2026 4:17 AM UTC
Answered

How do I know which line the first row of the current column is in the article?

Hello everyone.

If I select some rows, the first line of the current column is this:
curLine0=app.selection[0].textColumns[0].lines[0];
Is there a simple way to know which line curLine0 is in the story?

Do I still need to count the characters?

 

    Manan JoshiCorrect answer
    Community Expert
    Oct 26, 2026 11:08 AM UTC

    @dublove 

    var selLN = sel.parentStory.characters.itemByRange(0, sel.textColumns[0].lines[0].index).lines.length;
    alert(selLN )

     

    -Manan

    18 replies

    Community Expert
    Oct 26, 2026 4:45 AM UTC

    use the following function, it will take as an input the line object and give back the line number in the parentStory.

    function getLineNoInParentStory(ln) {
    var parStory = ln.parentStory
    var idx = ln.index
    var idxList = parStory.lines.everyItem().index
    var lidx
    for(var i = 0 ; i < idxList.length ; i++) {
    if(idxList[i] == idx) {
    return parseInt(i) + 1

    }
    }
    return null
    }

    You call it like the

    var lineNo = getLineNoInParentStory(curLine0)

     

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Oct 26, 2026 5:54 AM UTC

    Hi ​@Manan Joshi 

    Do it also need to compare line by line?

    Your story is logically the same as mine below. If the story has 5000 or more lines, there will be a noticeable waiting time.

    var firstLinesSC = firstLinesSCGet();
    function firstLinesSCGet() {
    var sl = app.selection[0].parentStory.lines;
    for (i = 0; i < sl.length; i++) {
    if (sl[i] == app.selection[0].textColumns[0].lines[0]) {
    return i;
    }
    }
    }

     

    Translate
    Community Expert
    Oct 26, 2026 5:56 AM UTC

    I don’t think so running a 5000 iteration loop should not be that much and if you notice I am iterating over an array of number it is not a DOM hit. Try it and let me know

    In your code you are hitting the DOM in every iteration. I am not doing that

    Translate
    -Manan