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 // only do this if we have ctrl key..
52 var br = doc.createElement('br');
53 br.className = 'clear';
54 br.setAttribute('style', 'clear: both');
55 sel.insertNode(br, 'after');
59 this.core.undoManager.addEvent();
60 this.core.fireEditorEvent(e);
64 // deal with <li> insetion
65 if (pli.innerText.trim() == '' &&
66 pli.previousSibling &&
67 pli.previousSibling.nodeName == 'LI' &&
68 pli.previousSibling.innerText.trim() == '') {
69 pli.parentNode.removeChild(pli.previousSibling);
71 this.core.undoManager.addEvent();
72 this.core.fireEditorEvent(e);
76 var li = doc.createElement('LI');
77 li.innerHTML = ' ';
78 if (!pli || !pli.firstSibling) {
81 pli.parentNode.insertBefore(li, pli.firstSibling);
83 sel.cursorText (li.firstChild);
85 this.core.undoManager.addEvent();
86 this.core.fireEditorEvent(e);