3 Replies Latest reply on Jul 22, 2010 9:12 AM by Harbs.

    How to select a para without para marks?

    Praveen10 Level 1

      Hi All,

       

      I want to select a para without para marks i.e., the para mark symbol found at the end of all the paragraphs. Pl. suggest.

       

      Thanks,

       

      Praveen

        • 1. Re: How to select a para without para marks?
          [Jongware] Most Valuable Participant

          app.selection[0].paragraphs[0].characters.itemByRange(0,app.selection[0].paragraphs[0].cha racters.length-2).select();

          (This does not work with the final paragraph in a story when it has *no* closing hard return, and you need to check what happens with inline tables and/or footnotes, as these tend to throw off proper character counts.)

          • 2. Re: How to select a para without para marks?
            Harbs. Level 6

            Another method which basically does the same thing (but written a little easier to read, and more complete):

             

            var para=app.selection[0].paragraphs.item(0);
            var startChar = para.characters.item(0);
            var endChar = para.characters.item(-1).contents == "\r" ? para.characters.item(-2) : para.characters.item(-1);
            app.select(para.texts.itemByRange(startChar,endChar));
            

             

            Harbs

            • 3. Re: How to select a para without para marks?
              Marc Autret Level 4

              As a first try, here is a function which might work in various contexts:

               

              function selectParagraph(/*Paragraph*/par, /*?bool*/includingEndmark)
              //----------------------------
              // Returns FALSE if the target is invalid, else returns TRUE
              // - Supports single Paragraph, or Paragraph range, or everyItem()
              // - If the target is empty (no character), move the insertion pt within
              {
              var p, ips, c = -1;
              
              try {
                   p=resolve(par.toSpecifier());
                   if( p && p.constructor == Array )
                        // converts everyItem into a range
                        p=p[0].parent.paragraphs.itemByRange(0,-1);
                   ips = p.insertionPoints;
                   }
              catch(_){}
              
              if( !ips ) return false;  // invalid specifier
              
              if( !includingEndmark )
                   c -= ((c=p.characters) && c.length && c[-1].contents=='\r');
                   
              ips.itemByRange(0,c).select();
              return true;
              }
              
              //----------------------------
              // Sample tests
              //----------------------------
              var pars = app.activeDocument.stories[0].paragraphs;
              
              // Single paragraph
              //----------------------------
              if( selectParagraph(pars[1]) )
                   alert( "Selection of the 2nd paragraph EXCLUDING end mark" );
              else
                   alert( "Unable to select the 2nd paragraph" );
              
              if( selectParagraph(pars[1], true) )
                   alert( "Selection of the 2nd paragraph INCLUDING end mark" );
              else
                   alert( "Unable to select the 2nd paragraph" );
              
              // Paragraph range
              //----------------------------
              if( selectParagraph(pars.itemByRange(1,2), true) )
                   alert( "Selection of paragraph range [1,2] INCLUDING end mark" );
              else
                   alert( "Unable to select the paragraph range [1,2]" );
              
              if( selectParagraph(pars.itemByRange(1,2)) )
                   alert( "Selection of paragraph range [1,2] EXCLUDING end mark" );
              else
                   alert( "Unable to select the paragraph range [1,2]" );
              
              // everyItem() support -- equiv. to itemByRange(0,-1)
              //----------------------------
              if( selectParagraph(pars.everyItem()) )
                   alert( "Selection of every paragraph EXCLUDING end mark" );
              else
                   alert( "Unable to select every paragraph" );
              
              if( selectParagraph(pars.everyItem(), true) )
                   alert( "Selection of every paragraph INCLUDING end mark" );
              else
                   alert( "Unable to select every paragraph" );
              

               

              @+

              Marc