Fixed bug when cursor reaches end of text