Fix caretPositionInternal bound checking when content changed.

The new Logical() method does not report out-of-bound positions
accurately.