Continue stripping trailing whitespace to file without affecting cursor

This fixes a problem with the cursor jumping when typing too slowly with indentations or intentional trailing spaces.

Review @dinhviethoa