11 Replies Latest reply on Sep 1, 2015 6:57 AM by Johnwhite

    Ho to put insertPoint in the Parenthese?

    Johnwhite Level 1

      Hi experts

       

      This script for change contents of selection = "()"

      And underline = true; and move the insertPoint between the Partenthese.

       

      app.selection[0].underline = true;

      app.selection[0].contents = "()";

      app.selection = app.selection[0].insertionPoints[1];

       

      but what if I need both case

       

      1) selection is selected text;

      2) selection is insertPoint;

       

      like:

       

      app.selection[0].underline = true;

      app.selection[0].contents = "()";

      app.selection = app.selection[0].insertionPoints[1];

       

      or

       

      app.selection[0].underline = true;

      app.selection[0].contents = "()";

       

      my insert Point need to be in the Partenthese,

       

      How can I do that?

       

      Regard

      John

        • 1. Re: Ho to put insertPoint in the Parenthese?
          Jump_Over Level 5

          Hi,

           

          You could use insertionPoints.previousItem() and insertionPoints.nextItem() methods to navigate through selection but it can be a time-consuming solution.

           

          I suggest to use .index, like this:

           

          var
            cSelStart = app.selection[0].index,
            cSelEnd = cSelStart + app.selection[0].insertionPoints.length,
            cStory = app.selection[0].parentStory;
          
            app.selection[0].underline = true;
            cStory.insertionPoints[cSelStart].contents = "(";
            cStory.insertionPoints[cSelEnd].contents = ")";
            cStory.insertionPoints.itemByRange(cSelStart + 1, cSelEnd).select();
          

           

          Assumed text is selected (or cursor pointed)

           

          Jarek

          • 2. Re: Ho to put insertPoint in the Parenthese?
            Johnwhite Level 1

            Hi Jarek

             

            This is not what I want.

             

            It will just add a Partenthese at beginning and at end if some text is selected.

            I want: if something is selected is selected change it to "()"

            also selection is insert point has some comeout.

            thank you for you help, thank you so much.

             

            Regard

            John

            • 3. Re: Ho to put insertPoint in the Parenthese?
              hamdifem Level 1

              Why draw the bottom of the last bracket

              What to do avoid scratching the bottom of the last bracket

              • 4. Re: Ho to put insertPoint in the Parenthese?
                Johnwhite Level 1

                I want to change selected text or insert point contents to Partenthese then fill some figures.

                 

                like this (1,222,333)

                 

                if the target is a table cell

                if will help more quickly finish job

                 

                thanks

                 

                Regard

                John

                • 5. Re: Ho to put insertPoint in the Parenthese?
                  Jump_Over Level 5

                  Hi,

                   

                  Even if text is selected - just start typing so you will override selection, right?

                   

                  In case of removing ")" underline insert the line (after line#8):

                   

                  app.selection[0].characters[-1].underline = false;
                  

                   

                  Jarek

                  • 6. Re: Ho to put insertPoint in the Parenthese?
                    Laubender Adobe Community Professional & MVP

                    Hi John,

                    if you want to replace your selected text with "()" and if you want to set the cursor between the opening and closing paranthesis, the following snippet will work.
                    All text you are typing in will be underlined. The "()" will not be underlined. I hope, I get you right.

                     

                    // (Optional) Set the selected text to "no underline":
                    app.selection[0].texts[0].underline = false;
                    
                    // Replace the selected contents:
                    app.selection[0].contents = "()";
                    
                    // Define a new selection; the insertion point between the "()" :
                    app.select(app.selection[0].insertionPoints[1]);
                    
                    // Format the insertion point:
                    app.selection[0].underline = true;
                    
                    

                     

                    Uwe

                    • 7. Re: Ho to put insertPoint in the Parenthese?
                      Johnwhite Level 1

                      Thank you every one,

                       

                      I want to change the contents = "()", no matter the selection is some text or just a insert point

                      • 8. Re: Ho to put insertPoint in the Parenthese?
                        Johnwhite Level 1

                        and the make it underline, included Partenthese, and some text will be put.

                         

                        like:

                        case 1:

                         

                        if selection = insertPoint

                         

                        app.selection[0].InsertionPoint.contents = "()";

                         

                        then move the insert point between the Partenthese,

                         

                        case 2

                         

                        app.selection[0].underline = true;

                        app.selection[0].contents = "()";

                        app.selection = app.selection[0].insertionPoints[1];

                         

                        just one script for two cases, both working.

                         

                        is the possible to happen?

                         

                        thanks

                        Regard

                        John

                        • 9. Re: Ho to put insertPoint in the Parenthese?
                          Johnwhite Level 1

                          and the make it underline, included Partenthese, and some text will be put.

                           

                          like:

                          case 1:

                           

                          if selection = insertPoint

                           

                          app.selection[0].InsertionPoint.contents = "()";

                           

                          then move the insert point between the Partenthese,

                           

                          case 2

                           

                          app.selection[0].underline = true;

                          app.selection[0].contents = "()";

                          app.selection = app.selection[0].insertionPoints[1];

                           

                          just one script for two cases, both working.

                           

                          is the possible to happen?

                           

                          thanks

                          Regard

                          John

                          • 10. Re: Ho to put insertPoint in the Parenthese?
                            Laubender Adobe Community Professional & MVP

                            Then try this snippet:

                             

                            changeAndFormatContents();
                            
                            function changeAndFormatContents(){
                               
                                if(!app.selection[0].hasOwnProperty("baseline")){return};
                               
                                //Case: Text is selected
                               
                                //Case: A single insertion point is selected:
                            
                                if(app.selection[0].insertionPoints.length === 1){
                                   
                                    //Is the text in a story?
                                    if(app.selection[0].parent.constructor.name === "Story"){
                                       
                                        app.selection[0].underline = true;
                                        app.selection[0].contents = "()";
                                        app.select(app.selection[0].parent.insertionPoints[app.selection[0].index -1]);
                                        return;
                                       
                                        };
                                    //Is the text in a table cell?
                                    if(app.selection[0].parent.constructor.name === "Cell"){
                                       
                                        app.selection[0].underline = true;       
                                        app.selection[0].contents = "()";   
                                        app.select(app.selection[0].parent.texts[0].insertionPoints[app.selection[0].index -1]);
                                        return;
                                        };
                                   
                                    };
                            
                                //More than one insertion point is selected:
                                else{
                                   
                                    app.selection[0].texts[0].underline = true;
                                    app.selection[0].contents = "()";
                                    app.select(app.selection[0].insertionPoints[1]);
                                   
                                    };
                               
                                };
                            

                             

                            Uwe

                            • 11. Re: Ho to put insertPoint in the Parenthese?
                              Johnwhite Level 1

                              Thank you Uwe,

                               

                              thank you so much

                              It is so appreciate for being help,

                               

                              Regard

                              John