Ticket #3256: 3256_3.patch
File 3256_3.patch, 8.7 KB (added by , 14 years ago) |
---|
-
_source/plugins/domiterator/plugin.js
31 31 return next; 32 32 } 33 33 34 /** 35 * Evaluator for skipping bookmark nodes. 36 */ 37 function bookmarkEvaluator( node ) 38 { 39 return !( node && node.is && node.is ( 'span' ) 40 && node.hasAttribute( '_fck_bookmark' ) 41 || !node.is && !bookmarkEvaluator( node.getParent() ) ) 42 } 43 34 44 var iterator = function( range ) 35 45 { 36 46 if ( arguments.length < 1 ) … … 65 75 { 66 76 range = this.range.clone(); 67 77 range.enlarge( this.forceBrBreak ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS ); 78 79 var walker; 80 walker = new CKEDITOR.dom.walker( range ) 81 // Skip bookmark nodes. 82 walker.evaluator = bookmarkEvaluator; 83 this._.nextNode = walker.next(); 68 84 69 var boundary = range.getBoundaryNodes(); 70 this._.nextNode = boundary.startNode; 71 this._.lastNode = boundary.endNode.getNextSourceNode( true ); 85 range = range.clone(); 86 range.collapse(); 87 range.setEndAt( range.document.getBody(), CKEDITOR.POSITION_BEFORE_END ); 88 walker = new CKEDITOR.dom.walker( range ); 89 // Skip bookmark nodes. 90 walker.evaluator = bookmarkEvaluator; 91 this._.lastNode = walker.next(); 92 72 93 // Probably the document end is reached, we need a marker node. 73 94 if ( !this._.lastNode ) 74 95 { … … 73 94 if ( !this._.lastNode ) 74 95 { 75 96 this._.lastNode = range.document.createText( '' ); 76 this._.lastNode.insertAfter( boundary.endNode );97 range.document.getBody().append( this._.lastNode ); 77 98 } 78 99 79 100 // Let's reuse this variable. -
_source/plugins/justify/plugin.js
66 66 justifyCommand.prototype = { 67 67 exec : function( editor ) 68 68 { 69 var selection = editor.getSelection(), 70 range = selection && selection.getRanges()[0]; 71 72 if ( !range ) 69 var selection = editor.getSelection(); 70 if ( !selection ) 73 71 return; 74 72 75 73 var bookmarks = selection.createBookmarks(), 76 cssClassName = this.cssClassName, 77 iterator = range.createIterator(), 78 block; 79 80 while ( ( block = iterator.getNextParagraph() ) ) 81 { 82 block.removeAttribute( 'align' ); 74 ranges = selection.getRanges(); 83 75 84 if ( cssClassName )85 {86 // Remove any of the alignment classes from the className.87 var className = block.$.className =88 CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) );89 76 90 // Append the desired class name. 91 if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign ) 92 block.addClass( cssClassName ); 93 else if ( !className ) 94 block.removeAttribute( 'class' ); 95 } 96 else 77 var cssClassName = this.cssClassName, 78 iterator, 79 block; 80 for ( var i = ranges.length-1 ; i >= 0 ; i-- ) { 81 iterator = ranges[ i ].createIterator(); 82 while ( ( block = iterator.getNextParagraph() ) ) 97 83 { 98 if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign ) 99 block.setStyle( 'text-align', this.value ); 84 block.removeAttribute( 'align' ); 85 86 if ( cssClassName ) 87 { 88 // Remove any of the alignment classes from the className. 89 var className = block.$.className = 90 CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) ); 91 92 // Append the desired class name. 93 if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign ) 94 block.addClass( cssClassName ); 95 else if ( !className ) 96 block.removeAttribute( 'class' ); 97 } 100 98 else 101 block.removeStyle( 'text-align' ); 99 { 100 if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign ) 101 block.setStyle( 'text-align', this.value ); 102 else 103 block.removeStyle( 'text-align' ); 104 } 102 105 } 106 103 107 } 104 108 105 109 editor.focus(); -
_source/plugins/selection/plugin.js
868 868 createBookmarks : function( serializable ) 869 869 { 870 870 var retval = [], 871 ranges = this.getRanges(); 872 for ( var i = 0 ; i < ranges.length ; i++ ) 873 retval.push( ranges[i].createBookmark( serializable ) ); 871 ranges = this.getRanges(), 872 length = ranges.length; 873 // Adding bookmark in reverse order to avoid interacting. 874 for ( var i = length -1 ; i >= 0 ; i-- ) 875 // Defer the bookmark updates later after all ranges get processed. 876 retval.push( ranges[ i ].createBookmark( serializable, true ) ); 877 878 // Update all ranges to reflect the changes from bookmark adding.(#3475) 879 for ( i = length -1 ; i >= 0 ; i-- ) 880 ranges[ i ].moveToBookmark( retval[ i ], false ); 881 882 // Revert both back to sequenced order. 883 ranges.reverse(); 884 retval.reverse(); 885 886 // Generally it's enough to just update ranges caches. 887 this._.cache.ranges = ranges; 874 888 return retval; 875 889 }, 876 890 … … 887 901 888 902 selectBookmarks : function( bookmarks ) 889 903 { 890 var ranges = []; 891 for ( var i = 0 ; i < bookmarks.length ; i++ ) 904 var ranges = [], l = bookmarks.length; 905 906 // Removing bookmarks in sequence order to avoid interacting. 907 for ( var i = 0 ; i < l ; i++ ) 892 908 { 893 909 var range = new CKEDITOR.dom.range( this.document ); 894 range.moveToBookmark( bookmarks[ i] );910 range.moveToBookmark( bookmarks[ i ] ); 895 911 ranges.push( range ); 896 912 } 897 913 this.selectRanges( ranges ); -
_source/core/dom/range.js
363 363 * must contain ids, which can be used to restore the range even 364 364 * when these nodes suffer mutations (like a clonation or innerHTML 365 365 * change). 366 * @param {Boolean} [deferUpdate] Whether update the range to reflect 367 * the inserting of bookmark nodes or manually update it later. 366 368 * @returns {Object} And object representing a bookmark. 367 369 */ 368 createBookmark : function( serializable )370 createBookmark : function( serializable , deferUpdate ) 369 371 { 370 372 var startNode, endNode; 371 373 var baseId; … … 403 405 clone.collapse( true ); 404 406 clone.insertNode( startNode ); 405 407 406 // Update the range position. 407 if ( endNode ) 408 { 409 this.setStartAfter( startNode ); 410 this.setEndBefore( endNode ); 411 } 412 else 413 this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); 414 415 return { 408 var retval = { 416 409 startNode : serializable ? baseId + 'S' : startNode, 417 410 endNode : serializable ? baseId + 'E' : endNode, 418 411 serializable : serializable … … 417 410 endNode : serializable ? baseId + 'E' : endNode, 418 411 serializable : serializable 419 412 }; 413 414 if ( !deferUpdate ) 415 this.moveToBookmark( retval, false ); 416 417 return retval; 420 418 }, 419 421 420 422 421 /** 423 422 * Creates a "non intrusive" and "mutation sensible" bookmark. This … … 512 511 is2 : true // It's a createBookmark2 bookmark. 513 512 }; 514 513 }, 515 516 moveToBookmark : function( bookmark ) 514 515 /** 516 * Move the range position to what indicate by the bookmark and 517 * optionally remove the bookmark nodes. 518 * @param {Object} bookmark Any bookmark created via 519 * {@link CKEDITOR.dom.range::createBookmark} OR 520 * {@link CKEDITOR.dom.range.createBookmark2} functions. 521 * @param {Boolean} [dropNodes ] Whether remove the bookmark nodes after 522 * move to the destination position.(defaults to be 'true') 523 */ 524 moveToBookmark : function( bookmark, dropNodes ) 517 525 { 518 526 if ( bookmark.is2 ) // Created with createBookmark2(). 519 527 { … … 544 552 this.setStartBefore( startNode ); 545 553 546 554 // Remove it, because it may interfere in the setEndBefore call. 547 startNode.remove(); 555 if ( dropNodes !== false ) 556 startNode.remove(); 548 557 549 558 // Set the range end at the bookmark end node position, or simply 550 559 // collapse it if it is not available. … … 551 560 if ( endNode ) 552 561 { 553 562 this.setEndBefore( endNode ); 554 endNode.remove(); 563 if ( dropNodes !== false ) 564 endNode.remove(); 555 565 } 556 566 else 557 567 this.collapse( true );