Improve caret navigation behavior.

- Fixes an occasional segfault when manipulating input data.

- Reformats some code from previous pull request.
Merge branch 'master' of https://github.com/diath/Toxitty