Restore correct selection when region changed at end of selection

Fixes #1002314
Merge pull request #844 from sschaef/selection-lost

Restore correct selection when region changed at end of selection