CKEditor:设置光标/插入符号 [英] CKEditor: set cursor/caret positon

查看:889
本文介绍了CKEditor:设置光标/插入符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在CKEditor3.x中定位插入符号?
我有两个位置,并希望在两个位置使用insertHTML()。



虚构代码:

  editor.setCaret(20); // function not exists 
editor.insertHtml('::');
editor.setCaret(40); // function not exist
editor.insertHtml('::');

caret to position:20):

  var ranges = []; 
var range = new CKEDITOR.dom.range(this.document);
range.startOffset = 20;
range.endOffset = 20;
ranges.push(range);
editor.getSelection()。selectRanges(ranges);

解决方案

要在编辑器中插入文本或使用html做某事,



PS如果你可能想要的话,在dom操作后恢复光标位置,尝试此

  var s = editor.getSelection(); 
var selected_ranges = s.getRanges(); //保存所选范围
//做某事
s.selectRanges(selected_ranges); //恢复它


How can I position the caret in CKEditor3.x? I have 2 position and want use insertHTML() on both positons.

fictive code:

editor.setCaret(20); // function not exists
editor.insertHtml('::');
editor.setCaret(40); // function not exists
editor.insertHtml('::');

I have tried (to set caret to position: 20):

var ranges = [];
var range = new CKEDITOR.dom.range( this.document );
range.startOffset = 20;
range.endOffset = 20;
ranges.push( range );
editor.getSelection().selectRanges( ranges );

this is not working. :( Can anybody help me please?

解决方案

To insert text or do something with html in the editor you don't need to get the caret position.

Treat it as usual html.

P.S. If you probably want to restore cursor position after dom manipulating, try this

var s = editor.getSelection();
var selected_ranges = s.getRanges(); // save selected range
// do something
s.selectRanges(selected_ranges); // restore it

这篇关于CKEditor:设置光标/插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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