Some more fixes to the caret positioning code.