Ticket #3304: 3304_2.patch
File 3304_2.patch, 9.9 KB (added by , 14 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
1088 1088 case CKEDITOR.ENLARGE_BLOCK_CONTENTS: 1089 1089 case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS: 1090 1090 // DFS backward to get the block/list item boundary at or before the start. 1091 1092 // Get the boundaries nodes.1093 var startNode = this.getTouchedStartNode(),1094 endNode = this.getTouchedEndNode();1095 1096 if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary())1091 // Get the outter boundaries nodes. 1092 var startNode, endNode; 1093 1094 // Use bookmark nodes to mock boundary nodes for collapsed 1095 // range. 1096 if( this.collapsed ) 1097 1097 { 1098 this.setStartAt( startNode, 1099 CKEDITOR.dtd.$empty[ startNode.getName() ] ? 1100 CKEDITOR.POSITION_AFTER_END : 1101 CKEDITOR.POSITION_AFTER_START ); 1098 var bm = this.createBookmark(); 1099 startNode= bm.startNode; 1100 endNode = startNode; 1102 1101 } 1103 1102 else 1104 1103 { 1105 // Get the function used to check the enlaarging limits. 1106 var guardFunction = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ? 1107 CKEDITOR.dom.domWalker.blockBoundary() : 1108 CKEDITOR.dom.domWalker.listItemBoundary() ); 1109 1110 // Create the DOM walker, which will traverse the DOM. 1111 var walker = new CKEDITOR.dom.domWalker( startNode ); 1104 var boundaries = this.getBoundaryNodes(), 1105 startNode = boundaries.startNode, 1106 endNode = boundaries.endNode; 1107 } 1112 1108 1113 // Go walk in reverse sense. 1114 var data = walker.reverse( guardFunction ); 1115 1116 var boundaryEvent = data.events.shift(); 1109 // function used to check the enlarging limits. 1110 function checkOnBoundary( toNode, fromNode, customNodeNames ) 1111 { 1112 // Check the enlarged node. 1113 if( toNode && toNode.type == CKEDITOR.NODE_ELEMENT 1114 && toNode.isBlockBoundary( 1115 unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS? { br : 1 } : null ) ) 1116 return true; 1117 1117 1118 this.setStartBefore( boundaryEvent.from ); 1118 // Check the current node. 1119 else if( currentNode.type == CKEDITOR.NODE_ELEMENT && 1120 currentNode.isBlockBoundary( 1121 unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS? { br : 1 } : null ) 1122 && ( enlargedNode.$ == currentNode.$.parentNode 1123 || enlargedNode.$ == currentNode.$.previousSibling ) ) 1124 return true; 1119 1125 } 1120 1121 if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() ) 1126 1127 // Enlarging the start boundary. 1128 var walker = new CKEDITOR.dom.walker( startNode ), 1129 enlargedNode = startNode, 1130 currentNode = enlargedNode; 1131 while( enlargedNode ) 1122 1132 { 1123 this.setEndAt( endNode, 1124 CKEDITOR.dtd.$empty[ endNode.getName() ] ? 1125 CKEDITOR.POSITION_BEFORE_START : 1126 CKEDITOR.POSITION_BEFORE_END ); 1133 // Check for those opening element. 1134 if( !currentNode.getPrevious() && 1135 checkOnBoundary( currentNode.getParent(), currentNode ) ) 1136 break; 1137 enlargedNode = walker.previous(); 1138 if( checkOnBoundary( enlargedNode, currentNode ) ) 1139 break; 1140 currentNode = enlargedNode; 1127 1141 } 1128 else 1142 this.setStartAt( enlargedNode, CKEDITOR.POSITION_AFTER_END ); 1143 1144 // Enlarging the end boundary. 1145 walker = new CKEDITOR.dom.walker( endNode ), 1146 enlargedNode = endNode, 1147 currentNode = enlargedNode; 1148 while( enlargedNode ) 1129 1149 { 1130 // DFS forward to get the block/list item boundary at or before the end. 1131 walker.setNode( endNode ); 1132 data = walker.forward( guardFunction ); 1133 boundaryEvent = data.events.shift(); 1134 1135 this.setEndAfter( boundaryEvent.from ); 1150 // Check for those closing element. 1151 if( !currentNode.getNext() && 1152 checkOnBoundary( currentNode.getParent(), currentNode ) ) 1153 break; 1154 enlargedNode = walker.next(); 1155 if( checkOnBoundary( enlargedNode, currentNode ) ) 1156 break; 1157 currentNode = enlargedNode; 1158 } 1159 this.setEndAt( enlargedNode, CKEDITOR.POSITION_BEFORE_START ); 1160 1161 if( bm ) 1162 { 1163 // Backup current range. 1164 var enlargedBm = this.createBookmark(); 1165 1166 // Destroy the marker bookmark. 1167 this.moveToBookmark( bm ); 1168 this.moveToBookmark( enlargedBm ); 1136 1169 } 1137 1170 } 1138 1171 },