Bug in calculating difference between mask characters between old and new field values

A problem was noticed with the calculation of the difference between new and old mask count. This resulted in the caret being placed incorrectly when a mask character was added.

Re-masking was also not calculating the caret correctly

This pull request should fix it.