Caret position refactor.

Break single CaretPosition into having two caretPositionInternals.
Store caretPositionInternal as (lineIndex, positionWithinLine) pair.

Other minor improvements and API updates.