Fixes a crash in pasting at the end.