Roo.htmleditor.KeyEnter = function(cfg) {
Roo.apply(this, cfg);
Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
}
Roo.htmleditor.KeyEnter.prototype = {
core : false,
keypress : function(e)
{
if (e.charCode != 13 && e.charCode != 10) {
Roo.log([e.charCode,e]);
return true;
}
e.preventDefault();
var doc = this.core.doc;
var sel = this.core.getSelection();
var range = sel.getRangeAt(0);
var n = range.commonAncestorContainer;
var pc = range.closest([ 'ol', 'ul']);
var pli = range.closest('li');
if (!pc || e.ctrlKey) {
if (!e.ctrlKey) {
sel.insertNode('br', 'after');
} else {
var br = doc.createElement('br');
br.className = 'clear';
br.setAttribute('style', 'clear: both');
sel.insertNode(br, 'after');
}
this.core.undoManager.addEvent();
this.core.fireEditorEvent(e);
return false;
}
if (pli.innerText.trim() == '' &&
pli.previousSibling &&
pli.previousSibling.nodeName == 'LI' &&
pli.previousSibling.innerText.trim() == '') {
pli.parentNode.removeChild(pli.previousSibling);
sel.cursorAfter(pc);
this.core.undoManager.addEvent();
this.core.fireEditorEvent(e);
return false;
}
var li = doc.createElement('LI');
li.innerHTML = ' ';
if (!pli || !pli.firstSibling) {
pc.appendChild(li);
} else {
pli.parentNode.insertBefore(li, pli.firstSibling);
}
sel.cursorText (li.firstChild);
this.core.undoManager.addEvent();
this.core.fireEditorEvent(e);
return false;
}
};