Fix caret afterimage problem.
Improve calculating caret position.