I have the above problem because I am writing in mousedown, and I can write in mouseup.
The key is that the mouseup will trigger Afteredit, so you have to write in the mouseup instead of mousedown.