14 Replies Latest reply on Feb 17, 2016 1:31 AM by Marc Autret

    [JSX] On “Applying” a Paragraph Style through changeGrep() #override

    Marc Autret Level 4

      Hi fellows,

       

      In my document I temporarily use a special character (U+E100) that serves as a marker for applying some specific paragraph style:

       

      GrepRestyle01.png

       

      Then my script uses changeGrep() to both remove this marker and change the paragraph style at the corresponding location. It looks like this:

       

      var myDoc = app.properties.activeDocument,
          myBoldStyle = myDoc.paragraphStyles.itemByName('MyBoldStyle');
      
      // Init.
      app.findGrepPreferences = app.changeGrepPreferences = null;
      
      // Find the marker U+E100
      //    + the next char (captured in $1)
      app.findGrepPreferences.findWhat = "\uE100(.)";
      
      // Preset changeGrep so that it both removes the
      // marker and change the paragraph style.
      app.changeGrepPreferences.properties = {
          changeTo: '$1',
          appliedParagraphStyle: myBoldStyle,
      };
      
      // Go!
      myDoc.changeGrep();
      
      

       

      Note that findWhat looks for two characters: the marker "\uE100" and the next character which is saved into $1 thanks to the parentheses in the "\uE100(.)" pattern. Then changeGrepPreferences is preset so that the whole capture is changed into $1 (which removes the marker) while assigning the desired paragraph style (myBoldStyle).

       

      But I get two different results on two different platforms:

       

      GrepRestyle02.png

       

      GrepRestyle03.png

       

      First result is of course what I was expecting. On platform 2, however, the paragraph style is applied but the very first character—that is, our $1 variable in the GREP command—seems to retain its old attributes. In other words, myBoldStyle does not override the text formatting although it's usually assumed that changeText/changeGrep commands having an appliedParagraphStyle property should work in clearing mode. (See for example these discussions: changeGrep() clears overrides, or Preserve Manual Overrides .)

       

      My guess is there is in fact some Application or Document preference that controls this behavior, or maybe something related to the default paragraph style mechanism, but I don't find the needle in the haystack and can't figure out a generic solution to this issue. In case #2 all happens as if $1 was somehow “copied” with its own attributes, then the style applied, then $1 “pasted.”

       

      Any clue?

       

      Thanks for your help.

       

      @+

      Marc