Ticket #3475: 3475_3.patch
File 3475_3.patch, 7.9 KB (added by , 15 years ago) |
---|
-
_source/plugins/find/dialogs/find.js
279 279 this.removeHighlight(); 280 280 281 281 // Apply the highlight. 282 var range = this.toDomRange(); 282 var range = this.toDomRange(), 283 bookmark = range.createBookmark(); 283 284 highlightStyle.applyToRange( range ); 285 range.moveToBookmark( bookmark ); 284 286 this._.highlightRange = range; 285 287 286 288 // Scroll the editor to the highlighted area. … … 301 303 if ( !this._.highlightRange ) 302 304 return; 303 305 306 var bookmark = this._.highlightRange.createBookmark(); 304 307 highlightStyle.removeFromRange( this._.highlightRange ); 308 this._.highlightRange.moveToBookmark( bookmark ); 305 309 this.updateFromDomRange( this._.highlightRange ); 306 310 this._.highlightRange = null; 307 311 }, -
_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 ); -
_source/plugins/styles/plugin.js
119 119 { 120 120 applyStyle.call( this, document, true ); 121 121 }, 122 122 123 /** 124 * Apply the current style to the specified range. 125 * Note : the range will be mangled after this method, 126 * so the range should be bookmarked before invoking it. 127 * 128 * @param {CKEDITOR.dom.range} range 129 * @example 130 * // Apply style defined as 'mystyle' to a range. 131 * var style = new CKEDITOR.style( editor.config.mystyle ); 132 * var bookmark = range.createBookmark(); 133 * style.spplyToRange( range ); 134 * range.moveToBookmark( bookmark ); 135 */ 123 136 applyToRange : function( range ) 124 137 { 125 138 return ( this.applyToRange = … … 130 143 : null ).call( this, range ); 131 144 }, 132 145 146 /** 147 * @see {@link CKEDITOR.style.applyToRange} 148 */ 133 149 removeFromRange : function( range ) 134 150 { 135 151 return ( this.removeFromRange = … … 305 321 // Get the DTD definition for the element. Defaults to "span". 306 322 var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span ); 307 323 308 // Bookmark the range so we can re-select it after processing.309 var bookmark = range.createBookmark();310 311 324 // Expand the range. 312 325 range.enlarge( CKEDITOR.ENLARGE_ELEMENT ); 313 326 range.trim(); … … 503 516 } 504 517 } 505 518 506 // this._FixBookmarkStart( startNode );507 508 range.moveToBookmark( bookmark );509 519 } 510 520 511 521 function removeInlineStyle( range ) … … 1030 1040 1031 1041 function applyStyle( document, remove ) 1032 1042 { 1033 // Get all ranges from the selection. 1034 var selection = document.getSelection(); 1035 var ranges = selection.getRanges(); 1043 // Creating bookmarks first, since the ranges might be dirty later then. 1044 var selection = document.getSelection(), 1045 bookmarks = selection.createBookmarks(), 1046 ranges = selection.getRanges(); 1036 1047 var func = remove ? this.removeFromRange : this.applyToRange; 1037 1048 1038 // Apply the style to the ranges. 1039 for ( var i = 0 ; i < ranges.length ; i++ ) 1049 // Apply the style to the ranges in reverse order to avoid 1050 // range changes could impact on others. (#3475) 1051 for ( var i = ranges.length - 1 ; i >= 0 ; i-- ) 1040 1052 func.call( this, ranges[ i ] ); 1041 1053 1042 // Select the ranges again. 1043 selection.selectRanges( ranges ); 1054 selection.selectBookmarks( bookmarks ); 1044 1055 } 1045 1056 })(); 1046 1057