Reputation: 2257
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?
Upvotes: 1
Views: 5407
Reputation: 12690
Using the CKEditor API I don't see such problem in the API demo
With Chrome, I've inserted a table and then I used the insert HTML button and it worked fine.
Upvotes: 2
Reputation: 324587
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/
Upvotes: 2