fixed edge case when selection ends with newline