Improve cursor behavior on first/last line.

* When first/last line is deleted, place cursor so it behaves consistently.
* When moving down from the last line, place cursor at end of line.
* When moving up from first line, place cursor at start of line.