js contenteditable - prevent from writing into newly inserted element
问题 I'm working on a simply syntax highlighter that replaces text with dom elements with classes. Say, I have a <div contenteditable="true"> Some text. | And some other text. </div> and the cursor is at the | pipe //if a user types foo <div contenteditable="true"> Some text. foo| And some other text. </div> // and I replace it, then set the selection after the inserted element <div contenteditable="true"> Some text. <span class="highlight-foo">foo</span>| And some other text. </div> but if you