title: Move caret to the end of a word in a tinyMCE editor
body: <p>I'm trying to build a function for my tinyMCE editor that wraps certain words with a span tag as you type, so far I have this which I'm using in the <code>init_instance_callback</code> option while initializing the tinyMCE instance:</p>
  
  <pre><code>function(ed) {
          ed.on('keyup', function () {
              var editor     = tinyMCE.get('content'),
                  regex      = new RegExp('test|abc', 'gi'),
                  oldContent = editor.getContent(),
                  newContent = oldContent.replace(regex, '&lt;span style="background-color: yellow;"&gt;$&amp;&lt;/span&gt;');
  
              // Save cursor position
              var marker = editor.selection.getBookmark(2);
  
              // Set new content in editor
              editor.setContent(newContent);
  
              // Move cursor to where it was
              editor.selection.moveToBookmark(marker);
          });
      }
  </code></pre>
  
  <p>Here's a fiddle with a working example: <a href="http://fiddle.tinymce.com/Jjeaab" rel="nofollow">http://fiddle.tinymce.com/Jjeaab</a></p>
  
  <p>It works fine while you're typing but as soon as you enter one of the matched words (in this case "test" or "abc") then the caret moves to the start of the word, I believe this is because I'm adding extra characters with the span element so the bookmark isn't setting properly after the word is wrapped, is there a way to fix this?</p>