I'm looking for some help to solve a strange bug happening to me.
I need to find all paragraphs with a given style, then I must insert a new paragraph before each of them.
I use a Grep search to find the paragraphs, then I try to create a new paragraph before each of them by using :
foundParagraph.insertionPoints.contents = "\r";
Unfortunatelly, the "\r" character is inserted inside the previous paragraph, instead of the end :
- I have "foo\rbar\r" ;
- I want to obtain "foo\r\rbar\r" - so I use barParagraph.insertionPoints.contents = "\r" ;
- the result is, for example, "fo\ro\rbar\r", so the "\r" character is inside the "foo" paragraph.
The position of the "\r" character inside the previous paragraph varies with the font size. I suppose that this could be a clue - but I have no idea of what's happening.
Would someone have an idea ?
Keep in mind that you need to loop into the found paragraphs / texts from the last element when you change the contents —otherwise the text references (insertionPoint offsets) become wrong during the process.
In your code, try to replace your myDoc.findGrep() statement by myDoc.findGrep(true). This returns the resulting array in reverse order.
Does it look better?