fix bug with caretPos=0