diff --git a/src/case/richeditor/niceditor/niceditor.js b/src/case/richeditor/niceditor/niceditor.js index 4d2bd97db..372083bcd 100644 --- a/src/case/richeditor/niceditor/niceditor.js +++ b/src/case/richeditor/niceditor/niceditor.js @@ -376,6 +376,34 @@ document.execCommand(cmd, false, args); }, + initSelection: function (newLine) { + var newLineHtml = this._isIE11Below() ? "

" : "


" + var el = this.elm.element; + var children = el.children(); + if (!children.length) { + // 如果编辑器区域无内容,添加一个空行,重新设置选区 + el.append(newLineHtml); + this.initSelection(); + return; + } + + var last = children.last(); + + if (newLine) { + // 新增一个空行 + var html = last.html().toLowerCase(); + var nodeName = last.nodeName; + if ((html !== "
" && html !== "") || nodeName !== "P") { + // 最后一个元素不是空行,添加一个空行,重新设置选区 + el.append(newLineHtml); + this.initSelection(); + return; + } + } + + this.setFocus(last[0]); + }, + _isChildOf: function(child, parent) { var parentNode; if(child && parent) { @@ -388,6 +416,13 @@ } } return false; + }, + + _isIE11Below: function() { + if (!BI.isIE()) { + return false; + } + return BI.getIEVersion() < 11; } }); }());