Keep cursor position in CKEditor when focus changes

I already read these three questions:

Refocus CKEditor at the right cursor position

Place the cursor at a specific position in CKEditor

How to set cursor position to end of text in CKEditor?

But none of them could help me.

For some reason, editor.getSelection () and editor.createRange () work for me.

Let me explain to you what I need. I have it: enter image description here

The drop-down list in front of "Tipo de Texto" loads 4 static values. Depending on the value selected, N values ​​are dynamically loaded into the "Texto" drop-down list. When a value is selected in the β€œTexto” drop-down list, I have the following javascript function that inserts text inside my CKEditor:

var strTexto = ddlTexto.options[ddlTexto.selectedIndex].value; CKEDITOR.instances.txtTexto.insertHtml(strTexto); 

The problem is this: when I have a large text in CKEditor and I select a value from the Tipo de Texto drop-down list, it performs a postback to load the values ​​of the Texto drop-down list, and CKEditor is updated, losing the cursor position. I already placed the UpdatePanel there, the screen does not β€œblink”, but for some reason CKEditor β€œupdates” itself, losing the cursor position in the same way.

I would like to know if there is a way to prevent this. Or maybe an effective way to keep the cursor position. Everything that works is valid. All I need is a way that alternates the selection of these two dropdownlists, I do not lose the cursor position in the editor.

I see no reason to post the code here, but if you find it necessary, I will. Just tell me what you want.

Thanks.

+1
source share

All Articles