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.
Quick drive-by comment: this may need to be batched with the other operation to avoid creating two separate Undo steps.  But the other operation is done on a timeout, which means we'd need to figure out a different fix that can occur after the '}' is typed rather than before.  Maybe after the `indentLine()` call, we could check if the rest of the line is nothing but whitespace, and remove it if so?  then the `indentLine()` & `replaceRange()` calls could be grouped together in a batch.