Fixed bug when the text selected was in the beginning or the ending.