4 Replies Latest reply on Jul 13, 2016 5:58 AM by Laubender

    Insert hyphen in reverse order

    karthiks94217840 Level 2

      Hi Friends,


      I was try to code for insert "DISCRETIONARY_HYPHEN" continue 3 line hyphen-nit word before added.

       

      First hyphen-nit "insertionPoints[0].contents" working fine. But, following all hyphen-nit (set) words before wrongly insert for "DISCRETIONARY_HYPHEN". (Insert one after one character before). I don't now how to control this problem. Please suggest friends.

       

      @I need: Correct insert  "DISCRETIONARY_HYPHEN":

       

      1 set:

      1.png

       

      @Problem: Wrong insert  "DISCRETIONARY_HYPHEN":

       

      2 & 3 sets:

      2.png

       

      I have place my code is below:

       

      function color3PlusHyphenateted() {
          var doc, stories, n, l, lastWords, firstWords, hyphenateted, isHyphanated, i, j, lwl, hyphenatetedLen, everyLastWord;
          doc = app.activeDocument;
          stories = doc.stories.everyItem().getElements().slice(0);
          l = stories.length;
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.findWhat = '\-$';
          for (n = 0; n < l; n++) {
              everyLastWord = stories[n].lines.everyItem().words[-1];
              lastWords = [0].concat([], everyLastWord.getElements().slice(0));
              everyLastWord = everyLastWord.findGrep();
              everyLastWord = [0].concat([], everyLastWord);
              firstWords = stories[n].lines.everyItem().words[0].getElements().slice(0);
              lwl = lastWords.length;
              hyphenateted = [];
              for (i = 0; i < lwl; i++) {
                  isHyphanated = ((everyLastWord[i] && everyLastWord[i].length) || (lastWords[i] === firstWords[i]));
                  if (isHyphanated) {
                      hyphenateted.push(lastWords[i]);
                  } else {
                      hyphenatetedLen = hyphenateted.length;
                      if (hyphenatetedLen > 2) {
                                         
                          for (j = i - hyphenatetedLen; j < i; j++) {
                              lastWords[j].fillColor = doc.swatches[5];
                              
                          }
      //****************************** Problem Start here ******************************************************************************
                                                    
                                  for (k = i - hyphenatetedLen; k > i; k++) {
                                  lastWords[k].insertionPoints[0].contents = SpecialCharacters.DISCRETIONARY_HYPHEN;   
                                  }                    
      //~                              alert(lastWords[j].contents);
                                      lastWords[k].insertionPoints[0].contents = SpecialCharacters.DISCRETIONARY_HYPHEN;
      
      
      //****************************** Problem End here ******************************************************************************                    
                      }
                      hyphenateted = [];
                  }
             }
          }
      }
      app.doScript(color3PlusHyphenateted, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'color3PlusHyphenateted');
      

                      

      How to write reversed order? Please suggest friends.

       

      Thanks in Advance