From 723f451b30ac1c7b44b6fb3e39be4c8fcb8b3d44 Mon Sep 17 00:00:00 2001 From: fay Date: Thu, 19 Jul 2018 14:54:29 +0800 Subject: [PATCH 1/3] 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; } }); }()); From b524ed05cdcc9357f2d7aeb33820f5af5c784f87 Mon Sep 17 00:00:00 2001 From: fay Date: Thu, 19 Jul 2018 15:11:35 +0800 Subject: [PATCH 2/3] update --- src/case/richeditor/niceditor/niceditor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/case/richeditor/niceditor/niceditor.js b/src/case/richeditor/niceditor/niceditor.js index b5aead581..5d0193263 100644 --- a/src/case/richeditor/niceditor/niceditor.js +++ b/src/case/richeditor/niceditor/niceditor.js @@ -377,7 +377,7 @@ }, initSelection: function (newLine) { - var newLineHtml = this._isIE10Below() ? "

" : "


" + var newLineHtml = this._isIE11Below() ? "

" : "


" var el = this.elm.element; var children = el.children(); if (!children.length) { @@ -418,11 +418,11 @@ return false; }, - _isIE10Below: function() { + _isIE11Below: function() { if (!BI.isIE()) { return false; } - return BI.getIEVersion() < 10; + return BI.getIEVersion() < 11; } }); }()); From 77b9af480ae580dfcaca3dedef87c362d3485a44 Mon Sep 17 00:00:00 2001 From: fay Date: Thu, 19 Jul 2018 15:23:11 +0800 Subject: [PATCH 3/3] update --- src/case/richeditor/niceditor/niceditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/case/richeditor/niceditor/niceditor.js b/src/case/richeditor/niceditor/niceditor.js index 5d0193263..372083bcd 100644 --- a/src/case/richeditor/niceditor/niceditor.js +++ b/src/case/richeditor/niceditor/niceditor.js @@ -394,7 +394,7 @@ var html = last.html().toLowerCase(); var nodeName = last.nodeName; if ((html !== "
" && html !== "") || nodeName !== "P") { - // 最后一个元素不是


,添加一个空行,重新设置选区 + // 最后一个元素不是空行,添加一个空行,重新设置选区 el.append(newLineHtml); this.initSelection(); return;