Introduction to cursor maintenance
This article is for developers who are building a text input field that offers a movable cursor and applies formatting in the same field. Whether the format is applied after every keystroke or after a special user action, you have to decide where to put the cursor after the text has been formatted.
If you are familiar with the problem of maintaining cursor position in a formatted input field, you may want to go straight to my source code.