Fix caret position on typing and clean empty links on paste