Fix for caret positioning on applying a new and adding characters before a mask character

This patch should fix issue #141 and addresses issues with caret positioning around masked characters (when not at the end of input)