[Editor][Optimization] Only change the selection end position when there is a selection when trimming trailing whitespaces