Ticket #3608: 3608_4.patch
File 3608_4.patch, 9.6 KB (added by , 16 years ago) |
---|
-
_source/plugins/list/plugin.js
377 377 ( editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'br' ) ); 378 378 paragraph.appendTo( body ); 379 379 ranges = [ new CKEDITOR.dom.range( doc ) ]; 380 ranges[0].selectNodeContents( paragraph ); 380 // IE exception on inserting anything when anchor inside <br>. 381 if ( paragraph.is( 'br' ) ) 382 { 383 ranges[ 0 ].setStartBefore( paragraph ); 384 ranges[ 0 ].setEndAfter( paragraph ); 385 } 386 else 387 ranges[ 0 ].selectNodeContents( paragraph ); 381 388 selection.selectRanges( ranges ); 382 389 } 383 390 } -
_source/core/dom/range.js
265 265 // check(Start|End)OfBlock. 266 266 function getCheckStartEndBlockEvalFunction( isStart ) 267 267 { 268 var hadBr = false ;268 var hadBr = false, bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ); 269 269 return function( node ) 270 270 { 271 // First ignore bookmark nodes. 272 if ( bookmarkEvaluator( node ) ) 273 return true; 274 271 275 if ( node.type == CKEDITOR.NODE_TEXT ) 272 276 { 273 277 // If there's any visible text, then we're not at the start. 274 278 if ( CKEDITOR.tools.trim( node.getText() ).length ) 275 279 return false; 276 }280 } 277 281 else 278 282 { 279 283 // If there are non-empty inline elements (e.g. <img />), then we're not … … 1119 1123 case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS: 1120 1124 1121 1125 // Enlarging the start boundary. 1122 var walkerRange = new CKEDITOR.dom.range( this.document ) ;1123 walkerRange.setStartAt(1124 this.document.getBody(), CKEDITOR.POSITION_AFTER_START );1126 var walkerRange = new CKEDITOR.dom.range( this.document ), 1127 body = this.document.getBody(); 1128 walkerRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START ); 1125 1129 walkerRange.setEnd( this.startContainer, this.startOffset ); 1126 1130 1127 1131 var walker = new CKEDITOR.dom.walker( walkerRange ), 1128 1129 guard = CKEDITOR.dom.walker.blockBoundary( 1132 blockBoundary, // The node on which the enlarging should stop. 1133 tailBr, // 1134 defaultGuard = CKEDITOR.dom.walker.blockBoundary( 1130 1135 ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null ), 1131 tailBr,1132 listGuard = function( node )1136 // Record the encountered 'blockBoundary' for later use. 1137 boundaryGuard = function( node ) 1133 1138 { 1134 var result = guard( node ); 1135 if ( !result && node.is && node.is( 'br' ) ) 1139 var retval = defaultGuard( node ); 1140 if ( !retval ) 1141 blockBoundary = node; 1142 return retval; 1143 }, 1144 // Record the encounted 'tailBr' for later use. 1145 tailBrGuard = function( node ) 1146 { 1147 var retval = boundaryGuard( node ); 1148 if ( !retval && node.is && node.is( 'br' ) ) 1136 1149 tailBr = node; 1137 return re sult;1150 return retval; 1138 1151 }; 1139 walker.guard = guard;1140 1152 1153 walker.guard = boundaryGuard; 1154 1155 1141 1156 if ( ( enlargeable = walker.lastBackward() ) ) 1157 { 1158 // It's the body which stop the enlaring if no block boundary found. 1159 blockBoundary = blockBoundary || body; 1160 1161 // Start the range at different position by comparing 1162 // the document position of it with 'enlargeable' node. 1142 1163 this.setStartAt( 1143 enlargeable, CKEDITOR.POSITION_BEFORE_START ); 1164 blockBoundary, 1165 blockBoundary.contains( enlargeable ) ? 1166 CKEDITOR.POSITION_AFTER_START : 1167 CKEDITOR.POSITION_AFTER_END ); 1168 } 1144 1169 1145 1170 // Enlarging the end boundary. 1146 1171 walkerRange = this.clone(); 1147 1172 walkerRange.collapse(); 1148 walkerRange.setEndAt( 1149 this.document.getBody(), CKEDITOR.POSITION_BEFORE_END ); 1173 walkerRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); 1150 1174 walker = new CKEDITOR.dom.walker( walkerRange ); 1175 1176 // tailBrGuard only used for on range end. 1151 1177 walker.guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? 1152 listGuard : guard; 1178 tailBrGuard : boundaryGuard; 1179 blockBoundary = null; 1180 // End the range right before the block boundary node. 1181 ; 1153 1182 if ( ( enlargeable = walker.lastForward() ) ) 1154 this.setEndAfter( enlargeable ); 1183 { 1184 // It's the body which stop the enlaring if no block boundary found. 1185 blockBoundary = blockBoundary || body; 1186 1187 // Start the range at different position by comparing 1188 // the document position of it with 'enlargeable' node. 1189 this.setEndAt( 1190 blockBoundary, 1191 blockBoundary.contains( enlargeable ) ? 1192 CKEDITOR.POSITION_BEFORE_END : 1193 CKEDITOR.POSITION_BEFORE_START ); 1194 } 1155 1195 // We must include the <br> at the end of range if there's 1156 1196 // one and we're expanding list item contents 1157 1197 if ( tailBr ) -
_source/plugins/domiterator/plugin.js
12 12 (function() 13 13 { 14 14 15 function isBookmarkNode( node )16 {17 return ( node && node.getName18 && node.getName() == 'span'19 && node.hasAttribute( '_fck_bookmark' ) )20 ||21 ( node && !node.getName && isBookmarkNode( node.getParent()) );22 }23 24 function ignoreBookmarkEvaluator( node )25 {26 return !isBookmarkNode( node );27 }28 29 30 /**31 * Find next source order node, ignore bookmark nodes and stop at the specified end node.32 * @param {Object} currentNode33 * @param {Object} endNode34 */35 function getNextSourceNode( currentNode, endNode, startFromSibling )36 {37 var next = currentNode;38 do39 {40 next = next.getNextSourceNode(41 startFromSibling, null, endNode );42 }43 while( isBookmarkNode( next ) )44 return next;45 }46 47 15 var iterator = function( range ) 48 16 { 49 17 if ( arguments.length < 1 ) … … 79 47 range = this.range.clone(); 80 48 range.enlarge( this.forceBrBreak ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS ); 81 49 82 var walker = new CKEDITOR.dom.walker( range ); 83 walker.evaluator = ignoreBookmarkEvaluator; 50 var walker = new CKEDITOR.dom.walker( range ), 51 ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true ); 52 // Avoid anchor inside bookmark inner text. 53 walker.evaluator = ignoreBookmarkTextEvaluator; 84 54 this._.nextNode = walker.next(); 85 86 55 // TODO: It's better to have walker.reset() used here. 87 56 walker = new CKEDITOR.dom.walker( range ); 88 walker.evaluator = ignoreBookmark Evaluator;57 walker.evaluator = ignoreBookmarkTextEvaluator; 89 58 var lastNode = walker.previous(); 90 this._.lastNode = getNextSourceNode( lastNode, null,true );59 this._.lastNode = lastNode.getNextSourceNode( true ); 91 60 // Probably the document end is reached, we need a marker node. 92 61 if ( !this._.lastNode ) 93 62 { … … 102 71 lastNode = this._.lastNode; 103 72 104 73 this._.nextNode = null; 105 106 74 while ( currentNode ) 107 75 { 108 76 // closeRange indicates that a paragraph boundary has been found, … … 230 198 if ( isLast ) 231 199 break; 232 200 233 currentNode = getNextSourceNode( currentNode, lastNode, continueFromSibling);201 currentNode = currentNode.getNextSourceNode( continueFromSibling, null, lastNode ); 234 202 } 235 203 236 204 // Now, based on the processed range, look for (or create) the block to be returned. … … 301 269 // lists) or the next sibling <li>. 302 270 303 271 this._.nextNode = ( block.equals( lastNode ) ? null : 304 getNextSourceNode( range.getBoundaryNodes().endNode, lastNode, true ) );272 range.getBoundaryNodes().endNode.getNextSourceNode( true, null, lastNode ) ); 305 273 } 306 274 } 307 275 … … 334 302 if ( !this._.nextNode ) 335 303 { 336 304 this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null : 337 getNextSourceNode( block, lastNode, true );305 block.getNextSourceNode( true, null, lastNode ); 338 306 } 339 307 340 308 return block; -
_source/core/dom/walker.js
353 353 { 354 354 return this.blockBoundary( { br : 1 } ); 355 355 }; 356 /** 357 * Whether the node is a bookmark node's inner text node. 358 */ 359 CKEDITOR.dom.walker.bookmarkContents = function( node ) 360 { 361 }, 356 362 363 /** 364 * Whether the to-be-evaluated node is a bookmark node OR bookmark node 365 * inner contents. 366 * @param {Boolean} contentOnly Whether only test againt the text content of 367 * bookmark node instead of the element itself(default). 368 * @param {Boolean} isReject Whether should return 'false' for the bookmark 369 * node instead of 'true'(default). 370 */ 371 CKEDITOR.dom.walker.bookmark = function( contentOnly, isReject ) 372 { 373 function isBookmarkNode( node ) 374 { 375 return ( node && node.getName 376 && node.getName() == 'span' 377 && node.hasAttribute('_fck_bookmark') ); 378 } 379 380 return function( node ) 381 { 382 var retval, parent; 383 // Is bookmark inner text node? 384 retval = ( node && !node.getName && ( parent = node.getParent() ) 385 && isBookmarkNode( parent ) ); 386 // Is bookmark node? 387 retval = contentOnly ? retval : retval || isBookmarkNode( node ); 388 return isReject ? !retval : !!retval; 389 }; 390 }; 391 357 392 })();