Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserve caret/bookmark position in tiny while using setContent

Tags:

tinymce

I am working on an open source product to allow collaborative editing in a CMS. The use case is the following: While user A is editing some tiny node user B updates the same node. Everything is working fine updating user's A tiny editor except preserving his cursor position. I.e.

var bookmark = editor.selection.getBookmark();
editor.setContent(content);
editor.selection.moveToBookmark(bookmark);

will not work if the contents have changed before the caret. http://tinymce.moxiecode.com/forum/viewtopic.php?id=20458 mentions that there would be an update to deal with this kind of situation, but is there something I could do now? Thank you in advance!

like image 443
ggozad Avatar asked Apr 27 '11 20:04

ggozad


1 Answers

This can be a fumbling thing to achieve, but here is a onother way. You could use a formalized bookmark. The code will look like

var bookmark = editor.selection.getBookmark(2, true);
editor.setContent(content);
editor.selection.moveToBookmark(bookmark);
like image 58
Thariama Avatar answered Jan 03 '23 11:01

Thariama