如何在CKEditor中将光标位置设置到文本末尾?
有没有办法将光标设置在 CKEditor 内容的末尾?
该开发人员也提出了问题,但没有收到答案:
http ://cksource.com/forums/viewtopic.php?f=11&t=19877&hilit=cursor+end
我想将焦点设置在 CKEditor 内文本的末尾。当我使用时:
ckEditor.focus();
它会将我带到 CKEditor 内已有文本的开头。
Is there a way to set the cursor to be at the end of the contents of a CKEditor?
This developer asked too, but received no answers:
http://cksource.com/forums/viewtopic.php?f=11&t=19877&hilit=cursor+end
I would like to set the focus at the end of the text inside a CKEditor. When I use:
ckEditor.focus();
It takes me to the beginning of the text already inside the CKEditor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
经过一番摆弄后,我已经让它可以使用以下代码:
这个想法是:
After a bit of fiddling, I've got it to work with the following code:
The idea is:
这是@peter-tracey 的类似答案。就我而言,我的插件正在插入引用。如果用户做出了选择,我需要禁用该选择并将光标放在句子的末尾。
Here's a similar answer to @peter-tracey. In my case my plugin is inserting a citation. If the user has made a selection, I needed to disable the selection and place the cursor at the end of the sentence.
CKEditor 3.x:
基于开发人员提供的伪代码:
https://dev .ckeditor.com/ticket/9546#comment:3
CKEditor 3.x:
based on pseudo-code provided by the developers here:
https://dev.ckeditor.com/ticket/9546#comment:3
这是 ckeditor API 提供的最简单的解决方案。我已经在 IE10+、ff、safari 和 Chrome 上测试过:
This is the easiest solution provided by the ckeditor API. I have tested it on IE10+, ff, safari and Chrome:
这肯定会起作用。
CKEDITOR.config.startupFocus = '结束';
This will work for sure.
CKEDITOR.config.startupFocus = 'end';
您是否尝试过 ckEditor.Selection.Collapse(false);
have you tried ckEditor.Selection.Collapse(false);
根据 CKEditor 4 文档,另一个选项是:
链接: https: //ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dom_range.html#method-moveToElementEditablePosition
According to CKEditor 4 documentation, another option is:
Link: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dom_range.html#method-moveToElementEditablePosition
丹的回答对我来说得到了奇怪的结果,但微小的改变(除了拼写错误修复之外)使它起作用:
Dan's answer got strange results for me, but minor change (in addition to typo fix) made it work:
根据 CKEditor 4 的文档,一旦拥有编辑器对象,您就可以执行以下操作。
链接:http://docs.ckeditor.com/#!/api/CKEDITOR.dom.selection< /a> (在 selectRanges 函数下)。
According to the documentation for CKEditor 4, you can do the following once you have the editor object.
Link: http://docs.ckeditor.com/#!/api/CKEDITOR.dom.selection (under selectRanges function).