X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=3ec5db36f54f54dd845b18104cc04735018555c9;hp=d783d6652b9cc19811c35340a3ab75462255db45;hb=refs%2Ftags%2Fv3.0.1;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91 diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index d783d66..3ec5db3 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -11,6 +11,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var protectedSourceMarker = '{cke_protected}'; + + // Return the last non-space child node of the block (#4344). + function lastNoneSpaceChild( block ) + { + var lastIndex = block.children.length, + last = block.children[ lastIndex - 1 ]; + while( last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) ) + last = block.children[ --lastIndex ]; + return last; + } + function trimFillers( block, fromSource ) { // If the current node is a block, and if we're converting from source or @@ -18,8 +29,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // // Also, any   at the end of blocks are fillers, remove them as well. // (#2886) - var children = block.children; - var lastChild = children[ children.length - 1 ]; + var children = block.children, lastChild = lastNoneSpaceChild( block ); if ( lastChild ) { if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' ) @@ -31,11 +41,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function blockNeedsExtension( block ) { - if ( block.children.length < 1 ) - return true; - - var lastChild = block.children[ block.children.length - 1 ]; - return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; + var lastChild = lastNoneSpaceChild( block ); + return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; } function extendBlockForDisplay( block )