Fix mask bug

Caret position immediately following last valid caret position is allowed.
Code as it was written had set position following the last character (mask or otherwise) as valid.