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.
Normally `document.batchOperation()`, but within Editor it looks like we call the raw `cm.operation()` directly instead.