Ticket #3231: 3231_2.patch
File 3231_2.patch, 6.8 KB (added by , 15 years ago) |
---|
-
_source/tests/core/dom/range_shrink.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>CKEDITOR.dom.range</title> 5 <link rel="stylesheet" type="text/css" href="../../test.css" /> 6 <script type="text/javascript" src="../../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE% 7 <script type="text/javascript" src="../../../ckeditor.js"></script> 8 %REMOVE_LINE% --> 9 <script type="text/javascript" src="../../test.js"></script> 10 <script type="text/javascript"> 11 //<![CDATA[ 12 13 var tc; 14 15 CKEDITOR.test.addTestCase( tc = ( function() 16 { 17 // Local references. 18 var assert = CKEDITOR.test.assert, 19 arrayAssert = YAHOO.util.ArrayAssert; 20 21 var doc = new CKEDITOR.dom.document( document ); 22 23 /** 24 * Set the range with the start/end position specified by the locator, which in form of bookmark2. 25 * @param {Object} range 26 * @param {Array} startPosition range start path including offset 27 * @param {Array|Boolean} endPositoin range end path including offset or is collapsed 28 */ 29 function setRange( range, startPosition, endPositoin ) 30 { 31 var bm = { 32 end : null, 33 start : null, 34 is2: true, 35 startOffset : 0, 36 endoffset : 0 37 }; 38 bm.start = startPosition.slice( 0, startPosition.length - 1 ); 39 bm.startOffset = startPosition[ startPosition.length -1]; 40 if( endPositoin === true ) 41 { 42 bm.end = bm.start.slice(); 43 bm.endOffset = bm.startOffset; 44 } 45 else 46 { 47 bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); 48 bm.endOffset = endPositoin[ endPositoin.length -1 ]; 49 } 50 range.moveToBookmark( bm ); 51 } 52 53 function assumeRangeAreSame( range, startPosition, endPosition ){ 54 55 var bm = range.createBookmark2(); 56 bm.start.push( bm.startOffset ); 57 bm.end.push( bm.endOffset ); 58 arrayAssert.itemsAreEqual( startPosition, bm.start , 'Start positon not correct.' ); 59 if( endPosition !== true ) 60 arrayAssert.itemsAreEqual( endPosition, bm.end, 'End position not correct.' ); 61 } 62 63 return { 64 65 /** 66 * Shrink on element node boundary. 67 */ 68 test_shrink : function() 69 { 70 var range = new CKEDITOR.dom.range( doc ); 71 //<p><strong>This ^</strong>is^</p> 72 setRange( range, [ 1, 0, 0, 1 ], [ 1, 0, 2 ] ); 73 range.shrink(); 74 //<p><strong>This </strong>^is^</p> 75 assumeRangeAreSame( range, [1, 0, 1 ], [1, 0, 2 ] ); 76 }, 77 78 /** 79 * Shrink on text node boundary. 80 */ 81 test_shrink2 : function() 82 { 83 var range = new CKEDITOR.dom.range( doc ); 84 //<p><strong>This ^</strong>is^</p> 85 setRange( range, [ 1, 0, 0, 0, 5 ], [ 1, 0, 2 ] ); 86 range.shrink(); 87 //<p><strong>This </strong>^is^</p> 88 assumeRangeAreSame( range, [1, 0, 1 ], [1, 0, 2 ] ); 89 }, 90 name : document.title 91 }; 92 })() ); 93 94 //window.onload = tc.test_shrink2; 95 96 //]]> 97 </script> 98 </head> 99 <body><p><strong>This </strong>is</p></body> 100 </html> -
_source/plugins/selection/plugin.js
623 623 if ( !range.collapsed ) 624 624 { 625 625 range.optimize(); 626 626 range.shrink(); 627 627 node = range.startContainer; 628 628 629 629 if ( node.type != CKEDITOR.NODE_ELEMENT ) -
_source/core/dom/range.js
651 651 this.setEndAfter( container ); 652 652 } 653 653 }, 654 655 /** 656 * Decrease the range content to exclude particial selected node which doesn't have visual impact. 657 * Note: It only affect the range start position. 658 * @example 659 * Original range as: 660 * <p><strong>This ^</strong>is^</p> 661 * Will be transformed into the following: 662 * <p><strong>This </strong>^is^</p> 663 */ 664 shrink : function() 665 { 666 while( this.startOffset == ( this.startContainer.getChildCount ? 667 this.startContainer.getChildCount() : this.startContainer.getText().length ) ) 668 { 669 this.setStartAfter( this.startContainer ); 670 } 671 }, 654 672 655 673 trim : function( ignoreStart, ignoreEnd ) 656 674 { -
_source/core/dom/node.js
221 221 }, 222 222 223 223 /** 224 * Gets a DOM tree descendant under the current node.225 * @param {Array|Number} indices The child index or array of child indices under the node.226 * @returns {CKEDITOR.dom.node} The specified DOM child under the current node. Null if child does not exist.227 * @example228 * var strong = p.getChild(0);229 */230 getChild : function( indices )231 {232 var rawNode = this.$;233 234 if ( !indices.slice )235 rawNode = rawNode.childNodes[ indices ];236 else237 {238 while ( indices.length > 0 && rawNode )239 rawNode = rawNode.childNodes[ indices.shift() ];240 }241 242 return rawNode ? new CKEDITOR.dom.node( rawNode ) : null;243 },244 245 getChildCount : function()246 {247 return this.$.childNodes.length;248 },249 250 /**251 224 * Gets the document containing this element. 252 225 * @returns {CKEDITOR.dom.document} The document. 253 226 * @example -
_source/core/dom/element.js
1311 1311 this.$.parentNode.replaceChild( newNode.$, this.$ ); 1312 1312 newNode.$._cke_expando = this.$._cke_expando; 1313 1313 this.$ = newNode.$; 1314 }, 1315 1316 /** 1317 * Gets a DOM tree descendant under the current node. 1318 * @param {Array|Number} indices The child index or array of child indices under the node. 1319 * @returns {CKEDITOR.dom.node} The specified DOM child under the current node. Null if child does not exist. 1320 * @example 1321 * var strong = p.getChild(0); 1322 */ 1323 getChild : function( indices ) 1324 { 1325 var rawNode = this.$; 1326 1327 if ( !indices.slice ) 1328 rawNode = rawNode.childNodes[ indices ]; 1329 else 1330 { 1331 while ( indices.length > 0 && rawNode ) 1332 rawNode = rawNode.childNodes[ indices.shift() ]; 1333 } 1334 1335 return rawNode ? new CKEDITOR.dom.node( rawNode ) : null; 1336 }, 1337 1338 getChildCount : function() 1339 { 1340 return this.$.childNodes.length; 1314 1341 } 1315 1342 });