Ticket #3304: 3304.patch
File 3304.patch, 10.7 KB (added by , 15 years ago) |
---|
-
_source/plugins/find/dialogs/find.js
5 5 6 6 (function() 7 7 { 8 // Element tag names which prevent characters counting. 9 var characterBoundaryElementsEnum = 8 function guardDomWalkerNonEmptyTextNode( node ) 10 9 { 11 address :1, blockquote :1, dl :1, h1 :1, h2 :1, h3 :1, 12 h4 :1, h5 :1, h6 :1, p :1, pre :1, li :1, dt :1, de :1, div :1, td:1, th:1 13 }; 10 if ( node.type == CKEDITOR.NODE_TEXT && node.$.length > 0 ) 11 return true; 12 else 13 return false; 14 } 14 15 15 var guardDomWalkerNonEmptyTextNode = function( evt ) 16 /** 17 * Elements which break characters been considered as sequence. 18 */ 19 function checkCharactersBoundary ( node ) 16 20 { 17 if ( evt.data.to && evt.data.to.type == CKEDITOR.NODE_TEXT 18 && evt.data.to.$.length > 0 ) 19 this.stop(); 20 CKEDITOR.dom.domWalker.blockBoundary( { br : 1 } ).call( this, evt ); 21 }; 22 21 var dtd = CKEDITOR.dtd; 22 return node.isBlockBoundary( 23 CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) ); 24 } 23 25 24 26 /** 25 27 * Get the cursor object which represent both current character and it's dom … … 75 77 * Iterator which walk through document char by char. 76 78 * @param {Object} start 77 79 * @param {Number} offset 80 * @param {Boolean} isStrict 78 81 */ 79 var characterWalker = function( start, offset )82 var characterWalker = function( start, offset , isStrict ) 80 83 { 81 84 var isCursor = typeof( start.textNode ) !== 'undefined'; 82 85 this.textNode = isCursor ? start.textNode : start; … … 81 84 var isCursor = typeof( start.textNode ) !== 'undefined'; 82 85 this.textNode = isCursor ? start.textNode : start; 83 86 this.offset = isCursor ? start.offset : offset; 87 var walker = new CKEDITOR.dom.walker( this.textNode ); 88 walker[ isStrict? 'guard' : 'evaluator' ] = 89 guardDomWalkerNonEmptyTextNode; 84 90 this._ = { 85 walker : new CKEDITOR.dom.domWalker( this.textNode ),91 walker : walker, 86 92 matchBoundary : false 87 93 }; 88 94 }; … … 107 113 108 114 // If we are at the end of the text node, use dom walker to get 109 115 // the next text node. 110 var data = null; 111 while ( !data || ( data.node && data.node.type != 112 CKEDITOR.NODE_TEXT ) ) 116 var node = null; 117 while ( !node ) 113 118 { 114 data = this._.walker.forward( 115 guardDomWalkerNonEmptyTextNode ); 119 node = this._.walker.next( true ); 116 120 117 // Block boundary? BR? Document boundary? 118 if ( !data.node 119 || ( data.node.type !== CKEDITOR.NODE_TEXT 120 && data.node.getName() in 121 characterBoundaryElementsEnum ) ) 121 // Marking as match boundaries. 122 if( node === false 123 && checkCharactersBoundary( this._.walker.current ) ) 122 124 this._.matchBoundary = true; 125 // Already reach document end. 126 if ( !this._.walker.current ) 127 break; 128 123 129 } 124 this.textNode = data.node;130 this.textNode = node; 125 131 this.offset = 0; 126 132 return cursorStep.call( this ); 127 133 }, … … 138 144 } 139 145 140 146 // Start of text node -> use dom walker to get the previous text node. 141 var data = null; 142 while ( !data 143 || ( data.node && data.node.type != CKEDITOR.NODE_TEXT ) ) 147 var node = null; 148 while ( !node ) 144 149 { 145 data = this._.walker.reverse( guardDomWalkerNonEmptyTextNode );150 node = this._.walker.previous( true ); 146 151 147 // Block boundary? BR? Document boundary?148 if ( !data.node || ( data.node.type !== CKEDITOR.NODE_TEXT &&149 data.node.getName() in characterBoundaryElementsEnum) )152 // Marking as match boundaries. 153 if( node === false 154 && checkCharactersBoundary( this._.walker.current ) ) 150 155 this._.matchBoundary = true; 156 157 // Already reach document end. 158 if ( !this._.walker.current ) 159 break; 151 160 } 152 this.textNode = data.node;153 this.offset = data.node.length - 1;161 this.textNode = node; 162 this.offset = node.length - 1; 154 163 return cursorStep.call( this ); 155 164 } 156 165 }; … … 465 474 var cursors = this.range.getCursors(), 466 475 tail = cursors[ cursors.length - 1 ], 467 476 head = cursors[ 0 ], 468 headWalker = new characterWalker( head ),469 tailWalker = new characterWalker( tail );477 headWalker = new characterWalker( head, null, true ), 478 tailWalker = new characterWalker( tail, null, true ); 470 479 471 480 if ( ! ( isWordSeparator( 472 481 headWalker.back().character ) -
_source/core/loader.js
39 39 'core/dom/node' : [ 'core/dom/domobject', 'core/tools' ], 40 40 'core/dom/nodelist' : [ 'core/dom/node' ], 41 41 'core/dom/domobject' : [ 'core/dom/event' ], 42 'core/dom/domwalker' : [ 'core/dom/node', 'core/dom/element', 'core/dom/document' ], 43 'core/dom/range' : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/domwalker', 'core/dom/walker' ], 42 'core/dom/range' : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ], 44 43 'core/dom/text' : [ 'core/dom/node', 'core/dom/domobject' ], 45 44 'core/dom/walker' : [ 'core/dom/node' ], 46 45 'core/dom/window' : [ 'core/dom/domobject' ], -
_source/core/dom/range.js
1087 1087 1088 1088 // Get the boundaries nodes. 1089 1089 var startNode = this.getTouchedStartNode(), 1090 endNode = this.getTouchedEndNode(); 1090 endNode = this.getTouchedEndNode(), 1091 // Create the DOM walker, which will traverse the DOM. 1092 walker = new CKEDITOR.dom.walker(); 1093 // Get the function used to check the enlaarging limits. 1094 walker.guard = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ? 1095 CKEDITOR.dom.walker.blockBoundary() : 1096 CKEDITOR.dom.walker.listItemBoundary() ); 1091 1097 1092 1098 if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary() ) 1093 1099 { … … 1098 1104 } 1099 1105 else 1100 1106 { 1101 // Get the function used to check the enlaarging limits. 1102 var guardFunction = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ? 1103 CKEDITOR.dom.domWalker.blockBoundary() : 1104 CKEDITOR.dom.domWalker.listItemBoundary() ); 1105 1106 // Create the DOM walker, which will traverse the DOM. 1107 var walker = new CKEDITOR.dom.domWalker( startNode ); 1108 1107 walker.startNode = startNode; 1109 1108 // Go walk in reverse sense. 1110 var data = walker.reverse( guardFunction ); 1111 1112 var boundaryEvent = data.events.shift(); 1113 1114 this.setStartBefore( boundaryEvent.from ); 1109 var node = walker.lastBackward(); 1110 this.setStartBefore( node ); 1115 1111 } 1116 1112 1117 1113 if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() ) … … 1124 1120 else 1125 1121 { 1126 1122 // DFS forward to get the block/list item boundary at or before the end. 1127 walker.setNode( endNode ); 1128 data = walker.forward( guardFunction ); 1129 boundaryEvent = data.events.shift(); 1123 walker.reset(); 1124 walker.startNode = endNode; 1130 1125 1131 this.setEndAfter( boundaryEvent.from ); 1126 // Get the function used to check the enlaarging limits. 1127 node = walker.lastForward(); 1128 this.setEndAfter( node ); 1132 1129 } 1133 1130 } 1134 1131 }, -
_source/core/dom/walker.js
44 44 node = null; 45 45 } 46 46 else 47 node = this.startNode[ getSourceNodeFn ]( true, type, guard );47 node = this.startNode[ getSourceNodeFn ]( false, type, guard ); 48 48 49 49 while ( node && !this._.end ) 50 50 { … … 53 53 if ( node == this.endNode && !this.endInclusive ) 54 54 break; 55 55 56 if ( !this.evaluator &&this.evaluator( node ) !== false )56 if ( !this.evaluator || this.evaluator( node ) !== false ) 57 57 return node; 58 58 else if ( breakOnFalse && this.evaluator ) 59 59 return false; … … 67 67 68 68 function iterateToLast( rtl ) 69 69 { 70 var node, last ;70 var node, last = null; 71 71 72 72 while ( node = iterate.call( this, rtl ) ) 73 73 last = node; … … 162 162 * @returns {CKEDITOR.dom.node} The next node or null if no more 163 163 * nodes are available. 164 164 */ 165 next : function( )165 next : function( isGreedy ) 166 166 { 167 return iterate.call( this );167 return iterate.call( this , false, isGreedy ); 168 168 }, 169 169 170 170 /** … … 172 172 * @returns {CKEDITOR.dom.node} The previous node or null if no more 173 173 * nodes are available. 174 174 */ 175 previous : function( )175 previous : function( isGreedy ) 176 176 { 177 return iterate.call( this, true );177 return iterate.call( this, true, isGreedy ); 178 178 }, 179 179 180 180 /** … … 217 217 checkBackward : function() 218 218 { 219 219 return iterate.call( this, true, true ) !== false; 220 }, 221 222 /** 223 * Reset walker to initial state. 224 */ 225 reset : function() 226 { 227 delete this._.end; 228 delete this.current; 220 229 } 221 230 } 222 231 }); 232 233 /* 234 * Anything whose display computed style is block, list-item, table, 235 * table-row-group, table-header-group, table-footer-group, table-row, 236 * table-column-group, table-column, table-cell, table-caption, or whose node 237 * name is hr, br (when enterMode is br only) is a block boundary. 238 */ 239 var blockBoundaryDisplayMatch = 240 { 241 block : 1, 242 'list-item' : 1, 243 table : 1, 244 'table-row-group' : 1, 245 'table-header-group' : 1, 246 'table-footer-group' : 1, 247 'table-row' : 1, 248 'table-column-group' : 1, 249 'table-column' : 1, 250 'table-cell' : 1, 251 'table-caption' : 1 252 }, 253 blockBoundaryNodeNameMatch = { hr : 1 }; 254 255 CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames ) 256 { 257 var nodeNameMatches = CKEDITOR.tools.extend( 258 blockBoundaryNodeNameMatch, customNodeNames || {} ); 259 260 return blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] || 261 nodeNameMatches[ this.getName() ]; 262 }; 263 264 CKEDITOR.dom.walker.blockBoundary = function( customNodeNames ) 265 { 266 return function( node , type ) 267 { 268 return ! ( node.type == CKEDITOR.NODE_ELEMENT 269 && node.isBlockBoundary( customNodeNames ) ); 270 }; 271 }; 272 273 CKEDITOR.dom.walker.listItemBoundary = function() 274 { 275 return this.blockBoundary( { br : 1 } ); 276 }; 277 223 278 })();