You're absolutely right, this is a race condition, but I don't even know how I would do this the "correct" way. I'd have to stop using the `for` loop and then chain callback after callback for every single line. It would have to be, like, recursive callbacks or something. It would be insane.

In practise I don't think there's any harm if the lines get stripped out of order. It still has the desired effect of not breaking everything the way `setText` does.

Actually in my testing, I did notice the race condition having an effect: Open a document, put a dozen empty lines at the end, and then put a dozen spaces on one of the middle lines, then invoke the stripper. Even though the code says to strip spaces first and lines second, it strips the lines first, then the spaces second, leaving you still with extra newlines.

Doesn't bother me though, because then the next time you edit the document, those spaces will be gone, and it'll get the rest of the newlines.