开发者

TinyMCE on IE8: text cursor problem

开发者 https://www.devze.com 2023-01-23 05:53 出处:网络
when i type something on ie 8, and press \'bold\' on toolbar on top of the text editor开发者_JAVA百科, the cursor will go to the beginning of the entire text editor. is this bug in tiny mce?

when i type something on ie 8, and press 'bold' on toolbar on top of the text editor开发者_JAVA百科, the cursor will go to the beginning of the entire text editor. is this bug in tiny mce?

on the other hand, if i select text i typed, and pressed control+b, no problem ; both are fine in firefox,ie6


Have you tried turning off "View->Caret Browsing" in IE8 ? (it is toggled by F7)

  • That worked for me


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:

tinyMCE.init({..., onchange_callback: 'updateSelectionBookmark', ...});

This will call my 'updateSelectionBookmark' function when anything is changed on the screen, including the editor being blurred (Read more: http://tinymce.moxiecode.com/wiki.php/Configuration:onchange_callback). My updateSelectionBookmark looked something like:

function updateSelectionBookmark (ed) {
  ed.updatedSelectionBookmark = ed.selection.getBookmark(1);
}

This will add a custom property to the editor object which will always contain the latest bookmark.

I then make use of the stored bookmark whenever I need to add the content:

ed.selection.moveToBookmark(ed.updatedSelectionBookmark);

I wanted to insert HTML so I put this before my call to the instance command (In my case, mceInsertRawHTML).

I hope this helps someone, even if my answer is a few months late.

Edit (A few months later): 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:

tinyMCE.init({
  ...,
  setup: function (ed) {
    ed.onEvent.add(function (ed, e) {
      ed.updatedSelectionBookmark = ed.selection.getBookmark(1);
    });
  },
  ...
});

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.

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.


I would'nt say that it's a bug in IE8.
A cursor does'nt move by magic, someone(tinymce) put's him somewhere.
So if the cursor does'nt appear at the expected position, it has to be a misbehaviour in tinymce.

But I can't provide a "bugfix", because this not occurs with my IE8(Win7).
What's your environment?

0

精彩评论

暂无评论...
验证码 换一张
取 消