The only thing I can think of that would fix this is replacing spaces with
(non-breaking spaces), which would cause the entire thing to stay together and thus keep the space visible. However, longer blocks of code then would never break and would extend past the screen, because there are never any breaking points in it.
An alternate way is to add
before the actual space, without removing the space itself, which would show the physical space there while still wrapping on the regular space. It would be visually pleasing, but copying and pasting the code like that would render two spaces in the text.
Browsers wrap spaces like that, it's how they're designed. So, there's really nothing we can do about it without an extraordinary amount of work, and that amount of work just isn't feasible for something as minor as this.