Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I want to set cursor position manually to specific position in ckeditor. I have implemented short keys on some key press i am adding text using set data in ckeditor(ex. if i type "RnD+Space", it will replace with "research and development "). The problem is that after set data cursor will set to last at the end of all text. I want cursor will be there, where the text is replaced. Is this possible?
Posted
Updated 26-Jul-18 4:19am
v2
Comments
Kornfeld Eliyahu Peter 26-Apr-15 7:18am    
Try insertHTML instead of setData...
[no name] 26-Apr-15 7:53am    
Thanks for reply @Kornfeld Eliyahu Peter.
I don't know how to remove existing text(ex. if i have typed "eo+Space", then it will insert "Evolution of+Space" the word will become "eo Evolution of ").
I will not able to remove existing text that's why i have choose to go with "SetData".
Kornfeld Eliyahu Peter 26-Apr-15 8:49am    
Select the typed shortcut, than replace the selection content...
[no name] 28-Apr-15 0:35am    
Works only first time. Please check my new question. thanks.
http://www.codeproject.com/Questions/986224/CK-editor-find-and-replace-will-works-only-first-t

1 solution

Here's an undocumented hack you might want to play around with:

var selection = editor.getSelection();
var bookmarks = selection.createBookmarks(true);

// change / replace / delete text in editor

var range = selection.getRanges()[0];
range.moveToBookmark(bookmarks[0]);
range.select();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900