preserve the cursor position on unmask

This change solves the issue #196: unstable caret positioning when mask
changes on-the-fly.