implement getCaretPosition