it only fails when the replace it going upwards, probably the new replace position is not set correctly (in this case should be before the word and not after), jumping into the code ....
[EDIT] first observations on the following test code :
replacing TRAF_ by MY_TRAF_
-> after the first replace end gets changed in the correct direction but as : 0 ==> -=diff aka -=3 --> -3
and then we do in a new loop :
pos = control->FindText(data->start, data->end, data->findText, flags, &lengthFound); (8,-3, ..)
and this gives as pos : 3 .. and we're off ;-)
==> first (jumping to) conclusion : wxScintilla does not notice it's an illegal value and 'should' (?) return -1 so we now there's a wrap around, or we should cover that ourself
[EDIT2] :
first error in our code , when replacing :
data->start += lengthReplace;
should only be done when going down and no up, this causes us to be just after our replacement in this test case.
We should stay in front of the position where the text was found (pos), which just before became the new start position :
so we get :
if (data->directionDown)
{
data->start += lengthReplace
}
[EDIT 3] will also limit that end to 0 so it does not become negative