Ticket #2768: 2768_5.patch
File 2768_5.patch, 4.7 KB (added by , 15 years ago) |
---|
-
_source/plugins/styles/plugin.js
417 417 range.enlarge( CKEDITOR.ENLARGE_ELEMENT ); 418 418 419 419 var bookmark = range.createBookmark( true ), 420 startNode = range.document.getById( bookmark.startNode ), 421 startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ); 420 startNode = range.document.getById( bookmark.startNode ); 422 421 423 422 if ( range.collapsed ) 424 423 { 425 424 /* 426 425 * If the range is collapsed, try to remove the style from all ancestor 427 * elements, until either a block boundary is reached, or the style is 428 * removed. 426 * elements, until a block boundary is reached. 429 427 */ 428 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ); 430 429 for ( var i = 0, element ; i < startPath.elements.length && ( element = startPath.elements[i] ) ; i++ ) 431 430 { 432 431 if ( element == startPath.block || element == startPath.blockLimit ) … … 434 433 435 434 if ( this.checkElementRemovable( element ) ) 436 435 { 436 /* 437 * Before removing the style node, there may be a sibling to the style node 438 * that's exactly the same to the one to be removed. To the user, it makes 439 * no difference that they're separate entities in the DOM tree. So, merge 440 * them before removal. 441 */ 442 mergeSiblings( element ); 437 443 removeFromElement( this, element ); 438 break;439 444 } 440 445 } 441 446 } … … 446 451 * node via DFS and remove the styles one-by-one. 447 452 */ 448 453 var endNode = range.document.getById( bookmark.endNode ), 449 endPath = new CKEDITOR.dom.elementPath( endNode.getParent() ); 450 currentNode = startNode; 454 me = this; 451 455 452 // Find out the ancestor that needs to be broken down at startNode and endNode. 453 var breakStart = null, breakEnd = null; 454 for ( var i = 0 ; i < startPath.elements.length ; i++ ) 456 /* 457 * Find out the style ancestor that needs to be broken down at startNode 458 * and endNode. 459 */ 460 function breakNodes() 455 461 { 456 if ( this.checkElementRemovable( startPath.elements[ i ] ) ) 462 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ), 463 endPath = new CKEDITOR.dom.elementPath( endNode.getParent() ), 464 breakStart = null, 465 breakEnd = null; 466 for ( var i = 0 ; i < startPath.elements.length ; i++ ) 457 467 { 458 breakStart = startPath.elements[ i ]; 459 break; 468 var element = startPath.elements[ i ]; 469 470 if ( element == startPath.block || element == startPath.blockLimit ) 471 break; 472 473 if ( me.checkElementRemovable( element ) ) 474 breakStart = element; 460 475 } 461 } 462 for ( var i = 0 ; i < endPath.elements.length ; i++ ) 463 { 464 if ( this.checkElementRemovable( endPath.elements[ i ] ) ) 476 for ( var i = 0 ; i < endPath.elements.length ; i++ ) 465 477 { 466 breakEnd = endPath.elements[ i ]; 467 break; 478 var element = endPath.elements[ i ]; 479 480 if ( element == endPath.block || element == endPath.blockLimit ) 481 break; 482 483 if ( me.checkElementRemovable( element ) ) 484 breakEnd = element; 468 485 } 486 487 if ( breakEnd ) 488 endNode.breakParent( breakEnd ); 489 if ( breakStart ) 490 startNode.breakParent( breakStart ); 469 491 } 492 breakNodes(); 470 493 471 if ( breakEnd )472 endNode.breakParent( breakEnd );473 if ( breakStart )474 startNode.breakParent( breakStart );475 476 494 // Now, do the DFS walk. 477 while ( ( currentNode = currentNode.getNextSourceNode() ) && !currentNode.equals( endNode ) ) 495 var currentNode = startNode.getNext(); 496 while ( !currentNode.equals( endNode ) ) 478 497 { 479 if ( currentNode.type == CKEDITOR.NODE_ELEMENT ) 498 /* 499 * Need to get the next node first because removeFromElement() can remove 500 * the current node from DOM tree. 501 */ 502 var nextNode = currentNode.getNextSourceNode(); 503 if ( currentNode.type == CKEDITOR.NODE_ELEMENT && this.checkElementRemovable( currentNode ) ) 504 { 480 505 removeFromElement( this, currentNode ); 506 507 /* 508 * removeFromElement() may have merged the next node with something before 509 * the startNode via mergeSiblings(). In that case, the nextNode would 510 * contain startNode and we'll have to call breakNodes() again and also 511 * reassign the nextNode to something after startNode. 512 */ 513 if ( nextNode.type == CKEDITOR.NODE_ELEMENT && nextNode.contains( startNode ) ) 514 { 515 breakNodes(); 516 nextNode = startNode.getNext(); 517 } 518 } 519 currentNode = nextNode; 481 520 } 482 521 } 483 522