7 Replies Latest reply on Jun 29, 2015 2:12 AM by drerol74

    ScriptUI: textselection for edittext in InDesign CC 2014

    drerol74 Level 2

      Hello!

       

      Can anyone confirm that »textselection« for »edittext« no longer works for InDesign CC 2014?

      My system: Mac OS 10.9.5 and Indesign CC 2014.2


      What about Windows or CC 2015?

       

       

      #targetengine "textselection";
      
      var _ui = new Window ("palette");
      var _edittext = _ui.add ("edittext", undefined, "Please select this text!");
      var _showButton = _ui.add ("button", undefined, "Show selected text");
      var _exitButton = _ui.add ("button", undefined, "Cancel");
      
      _showButton.onClick = function ()  {
        alert(_edittext.textselection);
      }
      _exitButton.onClick = function ()  {
        _ui.close();
      }
      
      _ui.show ( );
      
      

       

       

      Roland

        • 1. Re: ScriptUI: textselection for edittext in InDesign CC 2014
          Marc Autret Level 4

          Hi Roland,

           

          Tested in Windows 7 your code does work in both

          • ID 9.3 x64 (CC),

          • ID 10.2.0.69 x64 (CC 2014.2)

          • ID 11.0.0.72 x64 (CC 2015.0)

           

          @+

          Marc

          • 2. Re: ScriptUI: textselection for edittext in InDesign CC 2014
            Laubender Adobe Community Professional & MVP

            Hi Roland,

            tested your code on Mac OSX 10.7.5 with:

            InDesign CS6 v8.1

            InDesign CC v9.3

            InDesign CC-2014.2

             

            CS6 has passed the test:

            MacOSX-10.7.5-ID-8.1.0.419.png

             

            CC and CC-2014.2 did not. Here an example from CC-2914.2:

            MacOSX-10.7.5-ID-10.2.0.69.png

             

            (I expanded your alert message with app.version)

             

            Uwe

             

            FWIW: Today the Adobe Forum pages seem to be terribly slow. I really had problem posting this message without seeing any freezes or timeouts.

            • 3. Re: ScriptUI: textselection for edittext in InDesign CC 2014
              Laubender Adobe Community Professional & MVP

              Now I tested with OSX 10.10.3 and InDesign CC-2015:

              Test not passed. Selected text is missing in the alert.

               

              Uwe

              • 4. Re: ScriptUI: textselection for edittext in InDesign CC 2014
                drerol74 Level 2

                Hi Marc and Uwe!

                 

                Thank you both for testing.

                 

                Then it is another problem with ScriptUI on Mac OS and CC. Oh dear! And no solution in sight.


                Roland

                • 5. Re: ScriptUI: textselection for edittext in InDesign CC 2014
                  Marc Autret Level 4

                  Hi Roland,

                   

                  > And no solution in sight.


                  No definitive solution but maybe a workaround. We can suppose that showButton's click, while causing the edittext to lost the focus also clears the selection (which it shouldn't, but that's probably the bug we're talking about.) In other words, as long as the edittext is active its textselection property might be OK. I doubt it is still valid at the 'blur' event time, but perhaps you could backup data on 'mouseout' (?)


                  Try this:


                  #targetengine 'textselection2'
                  
                  var _ui = new Window ("palette");
                  var _edittext = _ui.add ("edittext", undefined, "Please select this text!");
                  var _showButton = _ui.add ("button", undefined, "Show selected text");
                  var _exitButton = _ui.add ("button", undefined, "Cancel");
                  
                  // Backup the selection when mouseout occurs
                  // ---
                  _edittext.addEventListener('mouseout', function(/*ev*/){ this.backupSelection = this.textselection });
                  
                  _showButton.onClick = function(){ alert( _edittext.backupSelection ); };
                  
                  _exitButton.onClick = function(){ _ui.close(); }
                  
                  _ui.show ( );
                  

                   

                  Note, if such solution works, we must assume the mouse will quit the edittext area, which of course won't happen if the user only uses keyboard moves

                  But this approach can be improved as well by listening to keyboard events…

                   

                  @+

                  Marc

                  • 6. Re: ScriptUI: textselection for edittext in InDesign CC 2014
                    Laubender Adobe Community Professional & MVP

                    Hi Marc,

                    your solution to backup the text selection with a "mouseout" event is working well!

                    Just tested this with InDesign CC-2015.

                     

                    About using keyboard moves or commands:

                    1. Using TAB to advance from text selection to the next button:

                    The user might be aware, that text is not selected anymore and would not expect that anything is showing up in the alert.

                    In as much, that no keyboard command on a Mac would perform the execution of the button. At least not in this minimum code example.
                    Eg. hitting the enter key when focus is on the button will not execute the action. The user has to use the mouse to execute the button's action.

                     

                    2. Some "strange" things using an arrow key, the ESC key and the mouse to execute the button's action.

                    Problem: First I could not re-create this phenomenon. As it happened, it went like this:

                     

                    A. Select some text

                    B. Once hit the DOWN arrow key (in false hope to reach the button and in a later step to activate it); the cursor will go to the end of the text of the edittext field.
                    C. Once hit ESC so that the focus is not on the edittext field anymore

                    D. Use the mouse and hit the button labeled "Show selected text"

                     

                    => The alert will show the selected text from A !!??

                    How can we explain that?

                     

                    E. The contents of the edittext field will revert, if you edited text before doing A after hitting OK on the alert message.

                     

                    Ah. After testing on, I found the incredients to make that "work":
                    Do not use Roland's prepolutated contents, but edit the text before doing A from above so that some of the text is not visible anymore in the text edit field.

                    The amount of text has to be larger than the text edit field can show.

                     

                    All tested with InDesign CC-2015 on Mac OSX 10.10.3.

                     

                    Uwe

                    • 7. Re: ScriptUI: textselection for edittext in InDesign CC 2014
                      drerol74 Level 2

                      Hi Marc,

                       

                      you're right, the edittext is losing the selection by clicking on Button. It is a good idea to save the selected string in this way. As Uwe mentioned it works.

                       

                      But - unfortunately - this is only the first part of my problem.

                       

                      I also want insert a placeholder instead of selected text, when I click on the button.  I will make a further investigation.

                       

                       

                      Hi Uwe,

                      I also noticed a strange behavior with the following code: The first time it does not work, the second time it does (after edittext lose the focus).

                       

                      #targetengine 'textselection3' 
                      
                      var _ui = new Window ("palette"); 
                      var _edittext = _ui.add ("edittext", undefined, "Please select this text!"); 
                      var _showButton = _ui.add ("button", undefined, "Show selected text"); 
                      var _exitButton = _ui.add ("button", undefined, "Cancel"); 
                      
                      
                      
                      _edittext.addEventListener('blur', function(){
                        this.textselection = "(?#textselection?)";
                        this.text = this.text.replace("\\(\\?#textselection\\?\\)", "","");
                      }); 
                      
                      
                      
                      _showButton.onClick = function(){
                        //_edittext.textselection = "(?#textselection?)";
                        alert(_edittext.textselection);
                      }; 
                      
                      _exitButton.onClick = function(){ _ui.close(); } 
                      
                      _ui.show ( ); 
                      

                       

                       

                      Does this make sense for one of you?

                       

                       

                       

                        Roland