Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a similar problem where the image that I wanted to insert was always going to the top of the editor. I solved it by setting the 'onchange_callback' field in the editor's init:</p> <pre><code>tinyMCE.init({..., onchange_callback: 'updateSelectionBookmark', ...}); </code></pre> <p>This will call my 'updateSelectionBookmark' function when anything is changed on the screen, including the editor being blurred (Read more: <a href="http://tinymce.moxiecode.com/wiki.php/Configuration:onchange_callback" rel="nofollow">http://tinymce.moxiecode.com/wiki.php/Configuration:onchange_callback</a>). My updateSelectionBookmark looked something like:</p> <pre><code>function updateSelectionBookmark (ed) { ed.updatedSelectionBookmark = ed.selection.getBookmark(1); } </code></pre> <p>This will add a custom property to the editor object which will always contain the latest bookmark.</p> <p>I then make use of the stored bookmark whenever I need to add the content:</p> <pre><code>ed.selection.moveToBookmark(ed.updatedSelectionBookmark); </code></pre> <p>I wanted to insert HTML so I put this before my call to the instance command (In my case, mceInsertRawHTML).</p> <p>I hope this helps someone, even if my answer is a few months late.</p> <p><strong>Edit (A few months later):</strong> So I originally found this solution while working with TinyMCE 3.2.2.3 but we recently updated to 3.4.4 for compatibility with IE9. Looks like the above solution doesn't work as well as I thought it did. I've since found a (as far as I can tell) perfect solution to this. It's similar to the above except when and where to trigger the callback. Instead of using onchange_callback in the settings, you should use the editor's onEvent event:</p> <pre><code>tinyMCE.init({ ..., setup: function (ed) { ed.onEvent.add(function (ed, e) { ed.updatedSelectionBookmark = ed.selection.getBookmark(1); }); }, ... }); </code></pre> <p>This replaces the need for the updateSelectionBookmark function or the onchange_callback setting. The reason onEvent works better than onChange is because it gets called after any possible event, including mouse or key presses so the cursor's position is guaranteed to be saved even if moved but the content isn't changed.</p> <p>After setting up the editor with the above event callback, just use moveToBookmark as stated above to restore the selection. I've tested this on IE9, Chrome, FF6, it works when inserting images/text inside text/tables.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload