1 Reply Latest reply on May 16, 2012 11:19 AM by [Jongware]

    JS/CS5: Creating a HyperlinkTextDestination for a range of text

    rgartlan Level 1

      I'm having trouble getting a HyperlinkTextDestination set up for a range of text that's selected in my document.  It creates a destination, but it always results in being set to the beginning of the range, not the entire range.  I see the HyperlinkTextDestinations.add() function can accept an InsertionPoint or a Text, and it acts like it always prefers the former.  Am I doing something wrong here?  In the following code snippet, shouldn't the value of lengthOut be the same as lengthIn?

       

      Assume an open document with a range of text selected with the text tool.

       

      var doc = app.documents[0];

      if (doc.selection.length > 0)

      {

           var selection = doc.selection[0];

           if (selection != null)

           {

                var destText = selection; // using selection.getElements()[0] gives same result

                var lengthIn = destText.length;

                var newHLDest = doc.hyperlinkTextDestinations.add(destText, {name:selection.contents});

                // using destText.texts[0] above gives same result

                var lengthOut = newHLDest.destinationText.length;

                $.bp();

           }

      }

       

      Thanks.