Ckeditor在替换文本后获取光标位置并重新设置的内容。 [英] Ckeditor what to get cursor position and set again after replacing text.

查看:986
本文介绍了Ckeditor在替换文本后获取光标位置并重新设置的内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想手动将光标位置设置到 ckeditor 中的特定位置。我在一些按键上实现了短按键我在 ckeditor 中使用设置数据添加文本(例如,如果我键入RnD + Space,它将替换为研究与开发)。问题是设置数据后光标将设置为在所有文本结尾处持续。我想光标将在那里,文本被替换。这可能吗?

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?

推荐答案

这是一个你可能想玩的无证件黑客:



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


这篇关于Ckeditor在替换文本后获取光标位置并重新设置的内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆