Copy link to clipboard
Copied
Dear Friends and experts,
Has anyone of you ever tried to find something programmatically in a text selection (aka text range)? The Find method works from a starting point (Text Location) towards the end of a document. When I select a part of the document and issue the search, it obviously starts just after the selection...
oTR = oDoc.TextSelection;
oFindParms = GetFindParameters (..);
oTR1 = oDoc.Find(oTR.beg, oFindParms);
Even if the searched item is within the selection, the resulting oTR1 is behind the selction.
I have no idea how to do a search within the selection.
Once you have the TextRange structure you can do
var doc, textRange, textList;
...
// See if there is one or more anchored frames in the text range.
textList = doc.GetTextForRange (textRange, Constants.FTI_FrameAnchor);
Copy link to clipboard
Copied
Have just found this post and hope it will solve my problem:
This is a solution to find text, but how to find an Anchored Frame or a variable within the selection?
Copy link to clipboard
Copied
Once you have the TextRange structure you can do
var doc, textRange, textList;
...
// See if there is one or more anchored frames in the text range.
textList = doc.GetTextForRange (textRange, Constants.FTI_FrameAnchor);
Copy link to clipboard
Copied
Rick, excellent advice!
This works as expected - the found object is selected to indicate the find similar to the FM Find/Change dialogue.
KLD_Z.FindInSelection = function (sFType, sSearch) {
var oDoc = app.ActiveDoc, oTL, aTi, oTL, oTR = oDoc.TextSelection, oXX;
function ObjSelection (oXX) {
var oTL = oXX.TextLoc;
var oTL2 = new TextLoc (oTL.obj, oTL.offset+1);
var oTR = new TextRange (oTL, oTL2);
return oTR;
}
if (sFType == "ANCFRM") {
aTi = oDoc.GetTextForRange (oTR, Constants.FTI_FrameAnchor);
oXX = aTi[0].obj;
return ObjSelection (oXX);
} else if (sFType == "FOONOT") {
aTi = oDoc.GetTextForRange(oTR, Constants.FTI_FnAnchor);
oXX = aTi[0].obj;
return ObjSelection (oXX);
} else if (sFType == "TBLANY") {
aTi = oDoc.GetTextForRange(oTR, Constants.FTI_TblAnchor);
oXX = aTi[0].obj;
return ObjSelection (oXX);
}
} // --- end FindInSelection -----------------------------------------------
var oDoc, oTR;
oDoc=app.ActiveDoc;
$.bp(true);
// select text containing an anchored frame (ANCFRM), table (TBLANY)..
oTR = KLD_Z.FindInSelection ("TBLANY", "");
oDoc.TextSelection = oTR;