From 723f451b30ac1c7b44b6fb3e39be4c8fcb8b3d44 Mon Sep 17 00:00:00 2001 From: fay Date: Thu, 19 Jul 2018 14:54:29 +0800 Subject: [PATCH] update --- src/case/richeditor/niceditor/niceditor.js | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/case/richeditor/niceditor/niceditor.js b/src/case/richeditor/niceditor/niceditor.js index 4d2bd97db..b5aead581 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._isIE10Below() ? "

" : "


" + 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; + }, + + _isIE10Below: function() { + if (!BI.isIE()) { + return false; + } + return BI.getIEVersion() < 10; } }); }());