title: CKEditor cursor position after inserting uneditable element
body: <p>I'm having trouble in developing CKEditor plugins that insert uneditable contents into the text flow. I've been trying to utilize the range functions, but with little success as the documentation is less than stellar. So, given some text, lets say the plugin inserts "[[uneditable stuff]]" and then upon WYSIWYG display wraps that in a span so it can be styled in a color:</p>
  
  <p><code>&lt;p>This is some text[[uneditable stuff here]]&lt;/p></code></p>
  
  <p>When first inserting the uneditable stuff, we want the user to then be able to continue on typing or hitting Enter for a new line. The following code (which I got here: <a href="https://stackoverflow.com/questions/4536532/ckeditor-set-cursor-position-to-end-of-text">How to set cursor position to end of text in CKEditor?</a>) works in Firefox but (naturally) not in IE9, 8, or 7:</p>
  
  <pre><code>var s = editor.getSelection();
  editor.insertElement(e); // element 'e'= a span created earlier
  var p = e.getParent();
  s.selectElement(p);
  var selected_ranges = s.getRanges();
  selected_ranges[0].collapse(false);  //  false = to the end of the selected node
  s.selectRanges(selected_ranges);  // putting the current selection there
  </code></pre>
  
  <p>So what I want to happen is that the cursor goes at position "^":</p>
  
  <p><code>&lt;p>This is some text&lt;span>[[uneditable stuff here]]&lt;/span>^&lt;/p></code></p>
  
  <p>If the new element is not at the end of the line, then after creating it, the cursor should go to here:</p>
  
  <p><code>&lt;p>This is some text&lt;span>[[uneditable stuff here]]&lt;/span>^ with more text after the new element&lt;/p></code></p>
  
  <p>In FF, I can get the cursor at the end of the line though not at position after the new element. In IE, the cursor is still inside the new SPAN, which I see when I type and it is still in the span's css color, and when switching to SOURCE view, the text is gone (because it's an uneditable span).</p>
  
  <p>I know there's a range.setStartAfter method, but have been totally unable to make it work even in FF/Chrome.</p>
  
  <p>Does anybody have a really good handle on using range and selection methods in CKEditor? I know <em>I</em> don't!</p>
  
  <p>Starting to think that just using editor.insertElement is wrong, and I should learn about the FakeElement (insertBogus?) functions, which I don't understand, yet. Stock plugins for such as links and images don't seem to have this problem.</p>