3 * @class Roo.htmleditor.KeyEnter
5 * @cfg {Roo.HtmlEditorCore} core the editor.
8 * @param {Object} config Configuration options
15 Roo.htmleditor.KeyEnter = function(cfg) {
17 // this does not actually call walk as it's really just a abstract class
19 Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
22 //Roo.htmleditor.KeyEnter.i = 0;
25 Roo.htmleditor.KeyEnter.prototype = {
29 keypress : function(e)
31 if (e.charCode != 13 && e.charCode != 10) {
32 Roo.log([e.charCode,e]);
36 // https://stackoverflow.com/questions/18552336/prevent-contenteditable-adding-div-on-enter-chrome
37 var doc = this.core.doc;
41 var sel = this.core.getSelection();
42 var range = sel.getRangeAt(0);
43 var n = range.commonAncestorContainer;
44 var pc = range.closest([ 'ol', 'ul']);
45 var pli = range.closest('li');
46 if (!pc || e.ctrlKey) {
47 // on it list, or ctrl pressed.
49 sel.insertNode('br', 'after');
51 var br = doc.createElement('br');
52 br.className = 'clear';
53 br.setAttribute('style', 'clear:all');
54 sel.insertNode(br, 'after');
58 this.core.undoManager.addEvent();
59 this.core.fireEditorEvent(e);
63 // deal with <li> insetion
64 if (pli.innerText.trim() == '' &&
65 pli.previousSibling &&
66 pli.previousSibling.nodeName == 'LI' &&
67 pli.previousSibling.innerText.trim() == '') {
68 pli.parentNode.removeChild(pli.previousSibling);
70 this.core.undoManager.addEvent();
71 this.core.fireEditorEvent(e);
75 var li = doc.createElement('LI');
76 li.innerHTML = ' ';
77 if (!pli || !pli.firstSibling) {
80 pli.parentNode.insertBefore(li, pli.firstSibling);
82 sel.cursorText (li.firstChild);
84 this.core.undoManager.addEvent();
85 this.core.fireEditorEvent(e);