Ticket #3608: 3608_2.patch
File 3608_2.patch, 10.0 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 result; 1138 }; 1150 return retval; 1151 }, 1152 guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? 1153 tailBrGuard : boundaryGuard; 1154 1139 1155 walker.guard = guard; 1140 1156 1157 1141 1158 if ( ( enlargeable = walker.lastBackward() ) ) 1159 { 1160 // It's the body which stop the enlaring if no block boundary found. 1161 blockBoundary = blockBoundary || body; 1162 1163 // Start the range at different position by comparing 1164 // the document position of it with 'enlargeable' node. 1165 var position = blockBoundary.getPosition( enlargeable ); 1142 1166 this.setStartAt( 1143 enlargeable, CKEDITOR.POSITION_BEFORE_START ); 1167 blockBoundary, 1168 ( position | CKEDITOR.POSITION_CONTAINS | CKEDITOR.POSITION_PRECEDING ) 1169 == CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING ? 1170 CKEDITOR.POSITION_AFTER_START : 1171 CKEDITOR.POSITION_AFTER_END ); 1172 } 1144 1173 1145 1174 // Enlarging the end boundary. 1146 1175 walkerRange = this.clone(); 1147 1176 walkerRange.collapse(); 1148 walkerRange.setEndAt( 1149 this.document.getBody(), CKEDITOR.POSITION_BEFORE_END ); 1177 walkerRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); 1150 1178 walker = new CKEDITOR.dom.walker( walkerRange ); 1151 walker.guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? 1152 listGuard : guard; 1179 walker.guard = guard; 1180 blockBoundary = null; 1181 // End the range right before the block boundary node. 1182 ; 1153 1183 if ( ( enlargeable = walker.lastForward() ) ) 1154 this.setEndAfter( enlargeable ); 1184 { 1185 // It's the body which stop the enlaring if no block boundary found. 1186 blockBoundary = blockBoundary || body; 1187 1188 // Start the range at different position by comparing 1189 // the document position of it with 'enlargeable' node. 1190 var position = blockBoundary.getPosition( enlargeable ); 1191 debugger; 1192 this.setEndAt( 1193 blockBoundary, 1194 ( position | CKEDITOR.POSITION_CONTAINS | CKEDITOR.POSITION_PRECEDING ) 1195 == CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING ? 1196 CKEDITOR.POSITION_BEFORE_END : 1197 CKEDITOR.POSITION_BEFORE_START ); 1198 } 1155 1199 // We must include the <br> at the end of range if there's 1156 1200 // one and we're expanding list item contents 1157 1201 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
354 354 return this.blockBoundary( { br : 1 } ); 355 355 }; 356 356 357 /** 358 * Whether the node is a bookmark node's inner text node. 359 */ 360 CKEDITOR.dom.walker.bookmarkContents = function( node ) 361 { 362 }, 363 364 /** 365 * Whether the to-be-evaluated node is a bookmark node OR bookmark node 366 * inner contents. 367 * @param {Boolean} contentOnly Whether only test againt the text content of 368 * bookmark node instead of the element itself(default). 369 * @param {Boolean} isReject Whether should return 'false' for the bookmark 370 * node instead of 'true'(default). 371 */ 372 CKEDITOR.dom.walker.bookmark = function( contentOnly, isReject ) 373 { 374 function isBookmarkNode( node ) 375 { 376 return ( node && node.getName 377 && node.getName() == 'span' 378 && node.hasAttribute('_fck_bookmark') ); 379 } 380 381 return function( node ) 382 { 383 var retval; 384 if ( contentOnly ) 385 { 386 var parent; 387 retval = ( node && !node.getName && ( parent = node.getParent() ) 388 && isBookmarkNode( parent ) ); 389 } 390 else 391 retval = isBookmarkNode( node ); 392 return isReject ? !retval : retval; 393 }; 394 } 395 357 396 })();