Tinymce loses carriage position

I have a custom tinymce button that toggles the emoticons div next to the text box.

onclick : function() { ed.focus(); $('#my-input').toggleClass('with-emoticons'); $('#emoticons').toggleClass('emo-visible'); } 

When I click the button, the emoticons div shows, but the carriage goes from the end to the beginning of my text.

How to save carriage position when user button is pressed?

+6
source share
1 answer

It looks like you need to use a bookmark

 onclick : function() { ed.focus(); var bookmark = ed.selection.getBookmark(); $('#my-input').toggleClass('with-emoticons'); $('#emoticons').toggleClass('emo-visible'); ed.selection.moveToBookmark(bookmark); } 

The type of bookmarks used here is the html bookmark, which represents an invisible range in the html editor. The getBookmark function is also capable of creating non-html bookmarks. To do this, you can call ed.selection.getBookmark(2, true); . For more information on tinymce bookmarks, see docs .

+6
source

Source: https://habr.com/ru/post/920102/


All Articles