Keep cursor position in CKEditor when focus changes

≯℡__Kan透↙ 提交于 2019-12-11 07:50:17

问题


I have already read these three questions:

Refocus CKEditor at correct cursor position

Set cursor to 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() nor editor.createRange() work for me.

Let me explain you guys what I need. I have this:

The dropdownlist in front of "Tipo de Texto" loads 4 static values. Depending on the value that is selected, N values are dinamycally loaded into the "Texto" dropdownlist. When a value in the "Texto" dropdownlist is selected, I have the following javascript function that inserts the text inside my CKEditor:

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

The problem is: when I have a big text on the CKEditor and I select a value on the "Tipo de Texto" dropdownlist, it does a postback to load the values of the "Texto" dropdownlist and the CKEditor is refreshed, losing the position of the cursor. I've already put an UpdatePanel there, the screen doesn't "blinks", but for some reason CKEditor "refreshs" itself, losing the cursor position the same way.

I'd like to know if there is a way of preventing that. Or maybe an effective way for me to keep the cursor position. Anything that works, really. All I need is a way that alternating the selection of these two dropdownlists I don't loose the cursor position of the editor.

I don't see a reason to post code here, but if you think it's needed I will. Just tell me what you want.

Thank you.

来源:https://stackoverflow.com/questions/19016205/keep-cursor-position-in-ckeditor-when-focus-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!