I am currently working with contenteditable = "true" to create a syntax highlighted input field. I am writing a jquery plugin that converts an <input> to a container <div contenteditable="true"> . In detail, it hides the <input> and inserts the <div> container after it.
In my fiddle, the highlight function is just a simple replacement function to highlight everything "AND in the container." Here is my fiddle:
http://jsfiddle.net/3Rhz8/2/
If the contents of the container are changed, the plugin should
- synchronize content with input content
- update syntax highlighting
In my example, I just listen to the keyup event. Now there is a problem when I want to update the syntax highlighting of the container. When the input is changed using .html() or the innerHTML container property, the cursor state is reset. Is there a way to prevent this, or can I save / restore the cursor position?
source share