Display on/off quirks

Advocate ,
Nov 30, 2016

Copy link to clipboard

Copied

Dear experts

(FM-13.0.5.547) 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; 
  oTargetDoc.ScrollToText(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?

TOPICS
Scripting

Views

199

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Nov 30, 2016
frameexpert Adobe Community Professional , Nov 30, 2016
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.Cu...

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
Nov 30, 2016

Copy link to clipboard

Copied

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;

    }

}

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
K.Daube AUTHOR LATEST
Advocate ,
Dec 01, 2016

Copy link to clipboard

Copied

Thank you, Rick

Your ideas always make the functions more universal!

The only missing thing was

  doc.ScrollToText(textRange);  

before leaving restoreLocation

Klaus

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more