Improve replaceSelection cursor behavior