fix issue 8395

This is a PR to address #8395

I am not super happy about testing the nonWS again as is done below in the || comparison but I couldn't immediately think of a better way to do this.

As per the issue discussion, if the line has non-whitespace characters, the whitespace is not stripped.
@mackenza As I suggested in IRC, maybe moving cursor to end of (whitespace-only) line before performing edit is a simpler solution.