Skip to main content
K.Daube
Community Expert
Community Expert
November 8, 2021
Answered

Applied character format does not stop before ¶ mark

  • November 8, 2021
  • 1 reply
  • 421 views

In trying to resolve the problems in What's wrong with this find-raplace script? I have discovered (FM-15, but also FM-16), that it is not possible to assign a character format to a string ending before the ¶ mark. This mark always also gets the character format:

  • Have a word at the end of the paragraph: window¶
  • Select the word and apply the character format. What you want to see is window
  • But the paragraph mark also gets the character format: window¶

Hence searching for the character format brings up a very strange text range:

When inspecting this text range, I see

 

 

oTR = [object TextRange]
  beg = [object TextLoc]
    obj = [object Pgf] → ID 520257540
    offset = 7
  end = [object TextLoc]
    obj = [object Pgf] → ID 520257542
    offset = 0

 

I  have not found a method to find the real end of the thingy i want (it's not the current selection, it is the string with the searched character format). The following does not work:

 

#target framemaker
main ();

function main () {
  var oDoc = app.ActiveDoc, oPgf, oTLe, oTR, oTR2;
  
  oTR = oDoc.TextSelection;
  oPgf = oTR.beg.obj;
  oTR2 = new TextRange();
  oTR2.beg.obj = oTR.end.obj = oPgf;
  oTR2.beg.offset = oTR.beg.offset;
  oTR2.end.offset = Constants.FV_OBJ_END_OFFSET- 1;
  app.ActiveDoc.TextSelection = oTR2;
}

 

 

This topic has been closed for replies.
Correct answer frameexpert

The huge number doesn't prevent this from working:

var doc, pgf, textLoc;

doc = app.ActiveDoc;
pgf = doc.TextSelection.beg.obj;
textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);
doc.AddText (textLoc, "- At the end of the paragraph");

The length of the paragraph's text is not going to be reliable because you could have anchors in the paragraph (markers, tables, anchored frames) that will affect the offset value.

1 reply

frameexpert
Community Expert
Community Expert
November 8, 2021

Klaus, please try this:

 

#target framemaker

main ();

function main () {
    
  var oDoc = app.ActiveDoc, oPgf, oTLe, oTR, oTR2;
  
  oTR = oDoc.TextSelection;
  oPgf = oTR.beg.obj;
  oTR2 = new TextRange (
    new TextLoc (oPgf, oTR.beg.offset),
    new TextLoc (oPgf, Constants.FV_OBJ_END_OFFSET - 1));
  app.ActiveDoc.TextSelection = oTR2;
}
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
November 10, 2021

Unfortunately the properties of the text selection are still not correct:

oTR2.end.offset is this huge number and can not be used to insert something at the end of the paragraph.

I need to do it this way.

var oDoc = app.ActiveDoc, oPgf, oTR, oTR2, sText;
  oTR = oDoc.TextSelection;
  oPgf = oTR.beg.obj;
  sText = GetText (oDoc, oTR);
  oTR2 = new TextRange (
    new TextLoc (oPgf, oTR.beg.offset),
    new TextLoc (oPgf, oTR.beg.offset + sText.length));
  app.ActiveDoc.TextSelection = oTR2;
}

 This may be an error in ESTK for items fond by "search for character format".

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
November 10, 2021

The huge number doesn't prevent this from working:

var doc, pgf, textLoc;

doc = app.ActiveDoc;
pgf = doc.TextSelection.beg.obj;
textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);
doc.AddText (textLoc, "- At the end of the paragraph");

The length of the paragraph's text is not going to be reliable because you could have anchors in the paragraph (markers, tables, anchored frames) that will affect the offset value.