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

Here are some NUnit tests that show the new behavior: https://gist.github.com/lawrencejohnston/4a1b8ff1aaa98a8f0db3