Restore cursor buffer position after removing trailing newlines

This ensures that the cursor won't move when it's on the last line, no trailing newline exists, and it adds a trailing newline. Prior to this change the cursor would move to the new line that was added.

Fixes #17.