Fix bug where trailing whitespace wasn't stripped according to preference and terminal newlines weren't copied properly either.