2 Replies Latest reply on Dec 1, 2016 5:35 AM by K.Daube

    Display on/off quirks

    K.Daube Level 2

      Dear experts

      (FM- I have discovered a strange behaviour:
      In the following order the location is not restored after the actions. It seems that SetDisplay destroys it:

        SetDisplay (false);
        savedTR = goCurrentDoc.TextSelection;
      // Do a lot of things (loop) on various places in the document
        RestoreTR (goCurrentDoc, savedTR);
        SetDisplay (true);

      In the following order things work as expected. Cursor location is restored.

        savedTR = goCurrentDoc.TextSelection;
        SetDisplay (false);
      // Do a lot of things (loop) on various places in the document
        SetDisplay (true);
        RestoreTR (goCurrentDoc, savedTR);


      The two functions are

      function RestoreTR (oTargetDoc, oSavedTR) {
      // actions may have left us on a reference page
      var bodyPage = oTargetDoc.FirstBodyPageInDoc;  
        oTargetDoc.CurrentPage = bodyPage;  
        oTargetDoc.TextSelection = oSavedTR;  
      } //--- end RestoreTR 
      function SetDisplay (bWanted) {
        if (bWanted) {                // switch ON
          if (app.Displaying === 0) {
            app.Displaying = 1;
        } else {                      // switch OFF
          if (app.Displaying === 1) {
            app.Displaying = 0;
      } //--- end SetDisplay


      What may be the cause of this?

        • 1. Re: Display on/off quirks
          frameexpert Level 4

          Hi Klaus, I am not sure why this doesn't always work, but it may be that you don't always have a valid TextSelection when the script starts. Also, when you restore, you are assuming that you started on a body page. It may be better to have a "save" function that will be more specific about where you start. For example:


          function saveCurrentLocation (doc) {
              var location = {};
              location.pgf = doc.TextSelection.beg.obj;
              location.offset = doc.TextSelection.beg.offset;
              location.page = doc.CurrentPage;
              return location;


          Now your restore function may be more reliable:


          function restoreLocation (doc, location) {
              var textRange, pgf;
              doc.CurrentPage = location.page;
              pgf = location.pgf;
              if (pgf.ObjectValid () === 1) {
                  textRange = new TextRange (new TextLoc (pgf, location.offset),
                      new TextLoc (pgf, location.offset));
                  doc.TextSelection = textRange;
          • 2. Re: Display on/off quirks
            K.Daube Level 2

            Thank you, Rick

            Your ideas always make the functions more universal!

            The only missing thing was


            before leaving restoreLocation