开发者

Preserve caret/bookmark position in tiny while using setContent

开发者 https://www.devze.com 2023-03-01 07:35 出处:网络
I am working on an open source product to allow collaborative editing in a CMS. The use case is the following:

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!


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);
0

精彩评论

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