Q:

Chrome HTML document.execCommand('inserthtml' inserts into following table cell

I'm using ckEditor and am working on snippets/text-replacement functionality.  I have snippets that are either plain text strings or HTML strings (such as paragraph elements).  I'm using document.execCommand('inserthtml', false, html) to do my content insertion, and it works fine in most cases.
However, when I attempt to use this method to insert content into a table cell, the content winds up in the cell  after the one the cursor's in, or outside the table if the cursor is in the last cell.
My searching hasn't turned up much information on this situation, and I don't really understand why Chrome would act this way.  Is it intended behavior? Is there a better way to insert arbitrary html, maintaining cursor position?

A:

It seems to be a WebKit bug. You can work around it by using a custom replacement for the "InsertHTML" command. The following demo uses a function from my answer to a related question, preserves the caret position and works in IE < 9 (unlike the "InsertHTML" command, which does not).
http://jsfiddle.net/timdown/7SZjm/2/

