Fix issue with deleting multiple nodes at end of document.

The problem was that the selection was set to an invalid position afterwards.