I have several custom dialogs attached to toolbar buttons which do various things like insert links. Frequently (not always), when I call pasteHtml(), the content gets inserted at the top of the editor, rather than at the cursor position.
I understand that this is due to the editor losing focus, and therefore forgetting the cursor position. You can sort-of reproduce this in the demo editor. Place the cursor in the middle of the content somewhere, then click on a blank area of the toolbar, so that the editor loses focus. Then click the add link button and see that the link gets inserted at the top.(I know this is artificial, but I think it a useful demonstration of what happens.)
I am trying to figure out how to either prevent the loss of focus, or write some code which remembers the cursor position so that I can restore it before calling pasteHtml().
I tried calling editor.getSelection().getRange() after the button click, but the focus seems to already be lost, and the range object seems to refer to the top of the editor content. I also tried calling getRange() in OnClientSelectionChange, and also in a 'blur' event I attached to the content area. I have tried to set unselectable="on" in various places. None of these things helped.
I see that this behaves reliably in your built-in dialogs. So I wonder what I am doing wrong. (My custom dialogs are iframes contained in jQuery UI dialogs, which I don't think is too different in principle from your built-in dialogs.)
I understand that this is due to the editor losing focus, and therefore forgetting the cursor position. You can sort-of reproduce this in the demo editor. Place the cursor in the middle of the content somewhere, then click on a blank area of the toolbar, so that the editor loses focus. Then click the add link button and see that the link gets inserted at the top.(I know this is artificial, but I think it a useful demonstration of what happens.)
I am trying to figure out how to either prevent the loss of focus, or write some code which remembers the cursor position so that I can restore it before calling pasteHtml().
I tried calling editor.getSelection().getRange() after the button click, but the focus seems to already be lost, and the range object seems to refer to the top of the editor content. I also tried calling getRange() in OnClientSelectionChange, and also in a 'blur' event I attached to the content area. I have tried to set unselectable="on" in various places. None of these things helped.
I see that this behaves reliably in your built-in dialogs. So I wonder what I am doing wrong. (My custom dialogs are iframes contained in jQuery UI dialogs, which I don't think is too different in principle from your built-in dialogs.)