Yeah, this is the auto indentation at work, for better or worse.
I also end up with unwanted whitespace that was inserted by the auto indenter, and it'd be nice to have a clean way to get rid of it. Some editors delete the automatically inserted whitespace if you do anything other than typing after pressing enter, but I'm not terribly keep on this, due to it being so stateful (i.e., it would then be required to track which regions of text have been inserted due to auto indent).
Another possible option would be to automatically trim trailing whitespace on any line you edit, unless you're editing at the end of the line. Not sure if this would have some unintended consequences though.