4 Replies Latest reply on May 7, 2014 2:36 PM by Eiranix

    Getting insertionPoints properties

    Eiranix Level 1

      I am trying to find the line that the insertion point is on.

       

      I've tried several different combinations of this except the right one, can anyone help me out?

       

      alert(docRef.selection.insertionPoints.InsertionPoint.lines);

        • 1. Re: Getting insertionPoints properties
          pixxxel schubser Level 5

          This isn't  so easy.

           

          Depending on of your selection insertion point length can be "not available" or "1" or "more than 1". The parent is text range or story – not a line.

          For the beginning I can give you this:

          if(app.selection.insertionPoints.typename == 'InsertionPoints' ) {
              if(app.selection.insertionPoints.length == 1) {
              alert(app.selection.insertionPoints.parent.lines[0].contents);
              } else {
                  if (app.selection.insertionPoints.parent.length < app.selection.insertionPoints.parent.parent.insertionPoints.length) {
                  alert(app.selection.insertionPoints.parent.lines[0].contents);
                  }
              }
          }
          

           

          Note: This will show you the contents of the actual line, if the cursor is in the line or a part of the line is selected.

           

          Have fun

           

          • 2. Re: Getting insertionPoints properties
            Eiranix Level 1

            Great, thanks for the reply. I understand how it works now.

            Looks like there's no way to find the line number in the text frame, but I could possibly loop through the lines of the text frame to find it.

            It will have the unfortunate side effect of potentially getting more than one match if there is the same line elsewhere in the text frame... but I don't think there will be any way around that.

            • 3. Re: Getting insertionPoints properties
              CarlosCanto Adobe Community Professional & MVP

              you can insert a string unlikely to be found elsewhere ("+a_%-T#"), loop through the lines in the text frames, when you find your temp string you found your line number, delete the temp string.

              • 4. Re: Getting insertionPoints properties
                Eiranix Level 1

                Good idea, thanks for the tip Carlos.