Added more sophisticated cursor movement, so that it knows where
the line ends, but will only jump to the end of a shorter line if
it has to.