What's wrong with this find-replace script?
Dear all,
Colleague Thomas Becker used some of my scripts from the collection FMjsxLib to do this:
- Find the text-range with a particular character format ("window" - red)

- At the end of this range insert a closing quote and format it with "sCharFmtQuote"
- At the beginning of this range insert an opening quote and also format it with "sCharFmtQuote"

- Advance the text location behind the closing quote and find the next occurrence of "window".
Both the test document and the script are here (reduced to the minimum by me): enclose_with_double_quotes.zip
The main probem is here:
var trFind = new TextRange();
trFind.beg.obj = trFind.end.obj = tr.beg.obj;
trFind.beg.offset = tr.end.offset + sQuoteOpen.length + sQuoteClose.length;
trFind.end.offset = trFind.beg.offset;
$.bp(true);
tr = oDoc.Find(trFind.beg, findParams);
At he break point the variables have the status as shown to the left and after executing the next statement (find) the status depicted on t he right:

→ Although trFind points to the location after the closing quote, the object is found at the old location.
I have explicitly set up an independent object trFind, as I know that o2 = o1 makes not a copy of object o1, but an 'alias'. What's going wrong here?
The second problem i see is this
- The closing quote is inserted and formatted correctly (black)
- The opening quote is inserted, but not formatted correctly (red)
While inspecting this situation with the cursor and looking into the status line i discover this (the yellow higlight is just an idication):

- Moving the cursor from left to right via "ht " to the opening quote and selecting it reports no character format.
- Moving the cursor from right to left via "mmiZ" to the opening quote and selecting it reports f "window". But this obviously overrun by colour red - not indicated by a *
Side note
The green wiggles after t he closing German quote are the result of an old bug, which was claimed to be fixed.

