5 Replies Latest reply on Feb 23, 2009 1:12 PM by Len Swierski-m5Cbo1

    [JS, CS3] Need help changing tabStop positions of selected text

    Level 1
      Hi all,
      I am writing a script to nudge the tabStop positions of selected text by one point at a time. Sometimes it will be only a tab character selected, and other times it could be several in the paragraph or maybe even the whole story. The problem I am encountering is that when I reference the tabStops as app.selection[0].tabStops it includes ALL the tabStops in the paragraph and NOT just the selected ones. Is there a way to get just the selected tabStops and add a point to their positions? It must be that my referencing is flawed. Thanks for any help.
      Regards,
      Len Swierski
        • 1. Re: [JS, CS3] Need help changing tabStop positions of selected text
          Level 1
          A little more info:
          When I select only a single tab character, the constructor name reports as "Character."
          However, when I select more than one character, the constructor name is "Text." When selecting all text (Cmd-A) the constructor name reports as "TextColumn." Could this be the reason for the bum referencing?
          Thanks,
          Len Swierski
          • 2. Re: [JS, CS3] Need help changing tabStop positions of selected text
            Level 1
            Hi Len,

            The selection is the text, not the tab stop. That is, even if you have selected a tab character, you have not selected a tab stop. To find out which tab stop corresponds to the tab character you have selected, you'll have to work out the location of the tab character in the text. You might want to take a look at the TabUtilities.jsx example script to see how to do this.

            Thanks,

            Ole
            • 3. Re: [JS, CS3] Need help changing tabStop positions of selected text
              Level 1
              Thanks for pointing me in the right direction, Ole.

              I looked over the TabUtilities.jsx script. Seems like what I need to do is to run a "for" statement to find the index numbers of all the tab characters and then create a new array for the SELECTED ones in that collection. Their index numbers should correspond to the tabStop index numbers, right? How to do this all, though. Whew! Putting my thinking cap on now.

              Regards,

              Len Swierski
              • 4. Re: [JS, CS3] Need help changing tabStop positions of selected text
                Level 1
                Hi Len,

                That's not a bad approach, but remember that there may be more tab characters than there are tab stops. I was thinking of getting the location of the selected tab stop relative to the left edge of the text frame (or column, if you're working with multi-column frames) and then comparing it to the location of the tab stop. But I think your approach will work just as well and be quicker.

                Also, remember that when you start moving tab stops around, the index of the tab stop within the tab stops collection can change. If you have tab stop A at 12pt and tab stop B at 16pt, then tab stop A will be item(0) and B will be item (1). But if you move A to 24pt, A will become item(1) and B will be item(0). The index of the tab stop is relative to its location on the tab ruler.

                Thanks,

                Ole
                • 5. Re: [JS, CS3] Need help changing tabStop positions of selected text
                  Level 1
                  Ole, thanks for that info.

                  It's becoming clearer for me now. I think I can avoid overlapping the tabStop positions by allowing for that somewhere in the script, but first things first. The task at hand will only require nudging the tabStops by one point plus or minus (I'll have 2 scripts with keyboard shortcuts set to CTRL-NUM+ and CTRL-NUM-) so I will keep them from getting close by just watching the tab panel for now. Thanks again for your help.

                  Regards,

                  Len Swierski