fix for #8395 

this PR addresses #8395 and is a 2nd attempt.  I refactored my fix based on feedback from @peterflynn and @redmunds in #8426
@mackenza The 1st condition seems to work great!

Can you describe a concrete case for the 2nd condition where you think this is desirable? In the 1st condition, the desire is to never leave whitespace at the end of a line *after* non-ws chars. But in the 2nd condition, I can't think of any case where the user intent is clear enough that we'd want to try to be smart about ws *between* non-ws chars.