Don’t crash when the region is outside the underlying string.

This re-instates behaviour from before the API work.

Fixed #1002302
Merge pull request #837 from dragos/issue/semantic-highlighting-crash

Don’t crash when the region is outside the underlying string.