Hi @ai8153 ,
With the cursor just set or with a selected range of characters, you could expand the text selection to the end of the story first and then do findGrep() on the selection, the selected text. To expand the text selection:
app.select
(
app.selection[0].parentStory.texts[0].insertionPoints.itemByRange
(
app.selection[0].insertionPoints[0] ,
app.selection[0].parentStory.insertionPoints[-1]
)
);
All in all this:
app.findGrepPreferences = null;
app.findChangeGrepOptions.searchBackwards = false;
app.findGrepPreferences.findWhat = "\\[|\\]";
var originalSelection = app.selection[0];
// Select text from the current insertion point to the end of the story:
app.select
(
app.selection[0].parentStory.texts[0].insertionPoints.itemByRange
(
app.selection[0].insertionPoints[0] ,
app.selection[0].parentStory.insertionPoints[-1]
)
);
// Run findGrep() on the selection:
var myFound = app.selection[0].findGrep();
// Select the first instance found:
if( myFound.length > 0 )
{
app.select( myFound[0] );
}else
{
// Restore your original selection:
app.select( originalSelection )
};
That would also find text in a table that is inserted after the current position of your cursor.
Note: The scope for findGrep(), the text selection, will not see into anchored text frames.
Regards, Uwe Laubender ( Adobe Community Expert )
... View more