Fix https://github.com/icsharpcode/AvalonEdit/issues/1

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the #develop open source product (the "Contribution"). My Contribution is licensed under the MIT License.

Here are some NUnit tests that show the new behavior: https://gist.github.com/lawrencejohnston/4a1b8ff1aaa98a8f0db3