3 * @class Roo.htmleditor.KeyEnter
5 * @cfg {Roo.HtmlEditorCore} core the editor.
8 * @param {Object} config Configuration options
13 Roo.htmleditor.KeyEnter = function(cfg) {
15 // this does not actually call walk as it's really just a abstract class
17 Roo.get(this.core.doc.body).on('keypress', this.keypress, this);
21 Roo.htmleditor.KeyEnter.prototype = {
25 keypress : function(e)
27 if (e.charCode != 13) {
31 // https://stackoverflow.com/questions/18552336/prevent-contenteditable-adding-div-on-enter-chrome
32 var doc = this.core.doc;
34 var docFragment = doc.createDocumentFragment();
37 var newEle = doc.createTextNode('\n');
38 docFragment.appendChild(newEle);
41 var range = this.core.win.getSelection().getRangeAt(0);
42 var n = range.commonAncestorContainer ;
43 while (n && n.nodeType != 1) {
47 if (n && n.tagName == 'UL') {
48 li = doc.createElement('LI');
52 if (n && n.tagName == 'LI') {
53 li = doc.createElement('LI');
55 n.parentNode.insertBefore(li, n.firstSibling);
58 n.parentNode.appendChild(li);
62 range = doc.createRange();
63 range.setStartAfter(li);
66 //make the cursor there
67 var sel = this.core.win.getSelection();
68 sel.removeAllRanges();
74 //add the br, or p, or something else
75 newEle = doc.createElement('br');
76 docFragment.appendChild(newEle);
78 //make the br replace selection
80 range.deleteContents();
82 range.insertNode(docFragment);
83 range = range.cloneRange();
85 var sel = this.core.win.getSelection();
86 sel.removeAllRanges();