// Get the DTD definition for the element. Defaults to "span".\r
var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span );\r
\r
- // Bookmark the range so we can re-select it after processing.\r
- var bookmark = range.createBookmark();\r
-\r
// Expand the range.\r
range.enlarge( CKEDITOR.ENLARGE_ELEMENT );\r
range.trim();\r
}\r
}\r
\r
- firstNode.remove();\r
- lastNode.remove();\r
- range.moveToBookmark( bookmark );\r
+ // Remove the bookmark nodes.\r
+ range.moveToBookmark( boundaryNodes );\r
+\r
// Minimize the result range to exclude empty text nodes. (#5374)\r
range.shrink( CKEDITOR.SHRINK_TEXT );\r
}\r
\r
if ( this.checkElementRemovable( element ) )\r
{\r
- var endOfElement = range.checkBoundaryOfElement( element, CKEDITOR.END ),\r
- startOfElement = !endOfElement && range.checkBoundaryOfElement( element, CKEDITOR.START );\r
- if ( startOfElement || endOfElement )\r
+ var isStart;\r
+\r
+ if ( range.collapsed && (\r
+ range.checkBoundaryOfElement( element, CKEDITOR.END ) ||\r
+ ( isStart = range.checkBoundaryOfElement( element, CKEDITOR.START ) ) ) )\r
{\r
boundaryElement = element;\r
- boundaryElement.match = startOfElement ? 'start' : 'end';\r
+ boundaryElement.match = isStart ? 'start' : 'end';\r
}\r
else\r
{\r
\r
function applyStyle( document, remove )\r
{\r
- // Get all ranges from the selection.\r
- var selection = document.getSelection();\r
- var ranges = selection.getRanges();\r
- var func = remove ? this.removeFromRange : this.applyToRange;\r
-\r
- // Apply the style to the ranges.\r
- for ( var i = 0 ; i < ranges.length ; i++ )\r
- func.call( this, ranges[ i ] );\r
-\r
- // Select the ranges again.\r
- selection.selectRanges( ranges );\r
+ var selection = document.getSelection(),\r
+ // Bookmark the range so we can re-select it after processing.\r
+ bookmarks = selection.createBookmarks(),\r
+ ranges = selection.getRanges( true ),\r
+ func = remove ? this.removeFromRange : this.applyToRange,\r
+ range;\r
+\r
+ var iterator = ranges.createIterator();\r
+ while ( ( range = iterator.getNextRange() ) )\r
+ func.call( this, range );\r
+\r
+ if ( bookmarks.length == 1 && bookmarks[0].collapsed )\r
+ {\r
+ selection.selectRanges( ranges );\r
+ bookmarks[0].startNode.remove();\r
+ }\r
+ else\r
+ selection.selectBookmarks( bookmarks );\r
}\r
})();\r
\r