Get only the selected tabs

I have the chore of adusting thousands of tab stops in hundreds of paragraph styles and stole scripts useful to reset the tab stops. I thank anyone who has ever displayed such extract.

I thought it would be easy to write a tab-nudger, the idea being that the user could select a range of text containing tabs and add or subtract a point at a time, but only for tabs in the selection.

The obstacle is that

App.Selection [0]. TabStops

Returns all the tabs tab in the paragraph, even if the selected text contains only one or two of the related tab characters. So I guess that the script would somehow determine which tab stops at the point go with tab characters in the selection. But her party "somehow" left me speechless.

Hello

As you have noticed, each PointInsertion, Word, line, text has the same tabStops set as a parent.

Succesful edit tabStops associated with the current selection needs to discover:

  • How many legs (characters) are inside selection comparing to the whole paragraph.
  • tabStops how are defined for the current text selection (supposed to be at least as much as the number of tabs inside the paragraph)

Below the function returns an array that contains two elements:

Array [0] ==> number of defined tabs for the current selection (perhaps it is necessary to add some)

[1] table ==> table with the tabStops indexes associated tabs in the current selection.

function tabsFromSel() {
          var
                    tabStopsArr = [],
                    k, stop;

          if (!app.selection[0].hasOwnProperty ("baselineShift") ) return false;

          app.findTextPreferences.findWhat = "\t";
          var tabSel = app.selection[0].findText();

          if (!tabSel) return false;

          var
                    tabTot = app.selection[0].paragraphs[0].findText(),
                    len = tabTot.length,
                    lenSel = tabSel.length,
                    tabStopsDefined = app.selection[0].tabStops.length;

          while (len-->0)
                    if (tabTot[len]===tabSel[0])
                              break;

          stop = len + lenSel;
          for (k = len; k < stop; k++)
                    tabStopsArr.push(k);

return [tabStopsDefined, tabStopsArr];
}

So it could be a foundation for other changes (i.e. the user interaction with the dialog box)

Function returns false if there is No text_selection or without tab found inside the selection

Jarek

Tags: InDesign

Similar Questions

Maybe you are looking for