| 524 | | /* |
| 525 | | * If the range is collapsed, try to remove the style from all ancestor |
| 526 | | * elements, until a block boundary is reached. |
| 527 | | */ |
| 528 | | var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ); |
| 529 | | for ( var i = 0, element ; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ ) |
| | 532 | var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ), |
| | 533 | endPath = endNode? |
| | 534 | new CKEDITOR.dom.elementPath( endNode.getParent() ) : null, |
| | 535 | breakStart = null, |
| | 536 | breakEnd = null; |
| | 537 | for ( var i = 0 ; i < startPath.elements.length ; i++ ) |
| 534 | | if ( this.checkElementRemovable( element ) ) |
| 535 | | { |
| 536 | | /* |
| 537 | | * Before removing the style node, there may be a sibling to the style node |
| 538 | | * that's exactly the same to the one to be removed. To the user, it makes |
| 539 | | * no difference that they're separate entities in the DOM tree. So, merge |
| 540 | | * them before removal. |
| 541 | | */ |
| 542 | | mergeSiblings( element ); |
| 543 | | removeFromElement( this, element ); |
| 544 | | } |
| | 544 | if ( me.checkElementRemovable( element ) ) |
| | 545 | breakStart = element; |
| 580 | | if ( element == endPath.block || element == endPath.blockLimit ) |
| 581 | | break; |
| 582 | | |
| 583 | | if ( me.checkElementRemovable( element ) ) |
| 584 | | breakEnd = element; |
| | 559 | if ( breakEnd ) |
| | 560 | endNode.breakParent( breakEnd ); |
| | 561 | if ( breakStart ) |
| | 562 | { |
| | 563 | startNode.breakParent( breakStart ); |
| | 564 | // Here it's necessary to repair the broken node if nothing inputed. |
| | 565 | if ( range.collapsed ) |
| | 566 | { |
| | 567 | var checkingNode = startNode.getNext(); |
| | 568 | |
| | 569 | // Merge the broken nodes once after selection change OR before switch mode. |
| | 570 | function fixBroken( ev ){ |
| | 571 | var sel = ev.editor.getSelection(); |
| | 572 | sel.lock(); |
| | 573 | mergeElements( checkingNode, checkingNode.getPrevious() ); |
| | 574 | sel.unlock(); |
| | 575 | ev.removeListener(); |
| | 576 | } |
| | 577 | setTimeout( function(){ |
| | 578 | var editor = CKEDITOR.currentInstance; |
| | 579 | editor.on( 'selectionChange', fixBroken ); |
| | 580 | editor.on( 'unloadMode', fixBroken ); |
| | 581 | }, 100 ); |
| 594 | | // Now, do the DFS walk. |
| 595 | | var currentNode = startNode.getNext(); |
| 596 | | while ( !currentNode.equals( endNode ) ) |
| | 587 | // If the range is not collapsed, DFS walk forward to remove any conflicting styles. |
| | 588 | var currentNode = startNode.getNext(); |
| | 589 | while ( endNode && !currentNode.equals( endNode ) ) |
| | 590 | { |
| | 591 | /* |
| | 592 | * Need to get the next node first because removeFromElement() can remove |
| | 593 | * the current node from DOM tree. |
| | 594 | */ |
| | 595 | var nextNode = currentNode.getNextSourceNode(); |
| | 596 | if ( currentNode.type == CKEDITOR.NODE_ELEMENT && this.checkElementRemovable( currentNode ) ) |
| 605 | | // Remove style from element or overriding element. |
| 606 | | if( currentNode.getName() == this.element ) |
| 607 | | removeFromElement( this, currentNode ); |
| 608 | | else |
| 609 | | removeOverrides( currentNode, getOverrides( this )[ currentNode.getName() ] ); |
| 610 | | |
| 611 | | /* |
| 612 | | * removeFromElement() may have merged the next node with something before |
| 613 | | * the startNode via mergeSiblings(). In that case, the nextNode would |
| 614 | | * contain startNode and we'll have to call breakNodes() again and also |
| 615 | | * reassign the nextNode to something after startNode. |
| 616 | | */ |
| 617 | | if ( nextNode.type == CKEDITOR.NODE_ELEMENT && nextNode.contains( startNode ) ) |
| 618 | | { |
| 619 | | breakNodes(); |
| 620 | | nextNode = startNode.getNext(); |
| 621 | | } |
| | 612 | breakNodes(); |
| | 613 | nextNode = startNode.getNext(); |