您可以对onkeydown事件(在您自己的插件中)执行一些操作。如果光标已经在新的范围内,请添加刚键入的字符,否则将创建一个新的范围,并输入字符。像这样:
ed.onKeyDown.add(function(ed,evt){
char = getChar(evt.keyCode); // your function to get the character to be inserted depending on evt.keyCode
// if span already exists
node = ed.selection.getNode();
if (node.nodeName.toLowerCase() == 'span' && node.className == 'myclass'){
node.innerHTML += char;
}
// new span
else {
doc = ed.getDoc();
new_element = doc.createElement('span');
new_element.className = "myclass";
new_element.innerHTML = char;
tinymce.activeEditor.mceInsertContent(new_element);
}
})