Changes to fix the problem when xpp is typed.

When you type `abcdef` and then stand on the `b` and type `xpp` the text should become `acbbdef` with the cursor on the last `b`. Instead it becomes: `acbdbef` with the cursor on the `e`. The attached pull request solves this problem.