Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Display on/off quirks

Community Expert ,
Nov 30, 2016 Nov 30, 2016

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
361
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 30, 2016 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

...
Translate
Community Expert ,
Nov 30, 2016 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.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;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2016 Dec 01, 2016
LATEST

Thank you, Rick

Your ideas always make the functions more universal!

The only missing thing was

  doc.ScrollToText(textRange);  

before leaving restoreLocation

Klaus

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