X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fstyles%2Fplugin.js;h=3c6fedb59c908f2db5cb3121ea66d04efb89d777;hp=3af696c3eb50af9fad896c3efb7feff1ca967808;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hpb=055b6b0792ce7dc53d47af606b367c04b927c2ab diff --git a/_source/plugins/styles/plugin.js b/_source/plugins/styles/plugin.js index 3af696c..3c6fedb 100644 --- a/_source/plugins/styles/plugin.js +++ b/_source/plugins/styles/plugin.js @@ -376,9 +376,6 @@ CKEDITOR.STYLE_OBJECT = 3; // Get the DTD definition for the element. Defaults to "span". var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span ); - // Bookmark the range so we can re-select it after processing. - var bookmark = range.createBookmark(); - // Expand the range. range.enlarge( CKEDITOR.ENLARGE_ELEMENT ); range.trim(); @@ -544,9 +541,9 @@ CKEDITOR.STYLE_OBJECT = 3; } } - firstNode.remove(); - lastNode.remove(); - range.moveToBookmark( bookmark ); + // Remove the bookmark nodes. + range.moveToBookmark( boundaryNodes ); + // Minimize the result range to exclude empty text nodes. (#5374) range.shrink( CKEDITOR.SHRINK_TEXT ); } @@ -585,12 +582,14 @@ CKEDITOR.STYLE_OBJECT = 3; if ( this.checkElementRemovable( element ) ) { - var endOfElement = range.checkBoundaryOfElement( element, CKEDITOR.END ), - startOfElement = !endOfElement && range.checkBoundaryOfElement( element, CKEDITOR.START ); - if ( startOfElement || endOfElement ) + var isStart; + + if ( range.collapsed && ( + range.checkBoundaryOfElement( element, CKEDITOR.END ) || + ( isStart = range.checkBoundaryOfElement( element, CKEDITOR.START ) ) ) ) { boundaryElement = element; - boundaryElement.match = startOfElement ? 'start' : 'end'; + boundaryElement.match = isStart ? 'start' : 'end'; } else { @@ -1274,17 +1273,24 @@ CKEDITOR.STYLE_OBJECT = 3; function applyStyle( document, remove ) { - // Get all ranges from the selection. - var selection = document.getSelection(); - var ranges = selection.getRanges(); - var func = remove ? this.removeFromRange : this.applyToRange; - - // Apply the style to the ranges. - for ( var i = 0 ; i < ranges.length ; i++ ) - func.call( this, ranges[ i ] ); - - // Select the ranges again. - selection.selectRanges( ranges ); + var selection = document.getSelection(), + // Bookmark the range so we can re-select it after processing. + bookmarks = selection.createBookmarks(), + ranges = selection.getRanges( true ), + func = remove ? this.removeFromRange : this.applyToRange, + range; + + var iterator = ranges.createIterator(); + while ( ( range = iterator.getNextRange() ) ) + func.call( this, range ); + + if ( bookmarks.length == 1 && bookmarks[0].collapsed ) + { + selection.selectRanges( ranges ); + bookmarks[0].startNode.remove(); + } + else + selection.selectBookmarks( bookmarks ); } })();