Okay, I think I've got it.
Try moving the "ParseText_info.rawIndex = i + deletedChars + 1;" line to happen before the "checkAgain" if statement that currently precedes it. (Around line 2981) It seems to be producing the correct results now.