Ticket #3846: 3846.patch
File 3846.patch, 6.6 KB (added by , 15 years ago) |
---|
-
_source/plugins/selection/plugin.js
421 421 422 422 if ( !sel ) 423 423 type = CKEDITOR.SELECTION_NONE; 424 else if ( sel.rangeCount == 1 )424 else if ( sel.rangeCount == 1 && !sel.getRangeAt(0).collapsed ) 425 425 { 426 426 // Check if the actual selection is a control (IMG, 427 427 // TABLE, HR, etc...). 428 429 var range = sel.getRangeAt(0), 428 var range = this.getRanges()[ 0 ], 430 429 startContainer = range.startContainer; 431 430 432 if ( startContainer == range.endContainer433 && startContainer. nodeType == 1431 if ( startContainer.equals( range.endContainer ) 432 && startContainer.is 434 433 && ( range.endOffset - range.startOffset ) == 1 435 && styleObjectElements[ startContainer.childNodes[ range.startOffset ].nodeName.toLowerCase() ] ) 434 && startContainer.getChild( 435 range.startOffset ).getName() in styleObjectElements ) 436 type = CKEDITOR.SELECTION_ELEMENT; 437 // Webkit and Opera's element selection may leak into siblings 438 // nodes.( #3846) 439 else if ( CKEDITOR.env.webkit || CKEDITOR.env.opera ) 436 440 { 437 type = CKEDITOR.SELECTION_ELEMENT; 438 } 439 } 441 442 var walkerRange = range.clone(), 443 walker = new CKEDITOR.dom.walker( walkerRange ); 444 walker.guard = CKEDITOR.dom.walker.text( true, true ); 445 walker.evaluator = function( node ) 446 { 447 return node.is && node.getName() in styleObjectElements; 448 }; 449 var selectedElement = walker.next(); 450 walker.reset(); 451 if ( selectedElement && selectedElement.equals( walker.previous() ) ) 452 { 453 type = CKEDITOR.SELECTION_ELEMENT; 454 // Determinate the selected element now. 455 cache.selectedElement = selectedElement; 456 } 457 } 458 } 440 459 441 460 return ( cache.type = type ); 442 461 }, … … 694 713 */ 695 714 getSelectedElement : function() 696 715 { 716 var selectionType = this.getType(); 697 717 var cache = this._.cache; 698 718 if ( cache.selectedElement !== undefined ) 699 719 return cache.selectedElement; 700 720 701 721 var node; 702 703 if ( this.getType() == CKEDITOR.SELECTION_ELEMENT ) 722 if ( selectionType == CKEDITOR.SELECTION_ELEMENT ) 704 723 { 705 724 var sel = this.getNative(); 706 725 -
_source/core/dom/walker.js
304 304 lastBackward : function() 305 305 { 306 306 return iterateToLast.call( this, true ); 307 } 307 }, 308 308 309 } 309 /** 310 * Reset walker to initial state. 311 */ 312 reset : function() 313 { 314 delete this._.end; 315 delete this.current; 316 } 317 } 310 318 }); 311 319 312 320 /* … … 389 397 }; 390 398 }; 391 399 400 /** 401 * Whether the to-be-evaluated node is a text node. 402 * @param {Boolean} ignoreEmpty Whether count empty text node. 403 * @param {Boolean} isReject 404 */ 405 CKEDITOR.dom.walker.text = function( ignoreEmpty, isReject ) 406 { 407 return function( node ) 408 { 409 var retval = node && !node.is && ( !ignoreEmpty || node.getText().length ) 410 return isReject ? !retval : !!retval; 411 }; 412 }; 413 392 414 })(); -
_source/tests/plugins/selection/selection.html
2 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 3 <head> 4 4 <title>Plugin: selection</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 6 <link rel="stylesheet" type="text/css" href="../../test.css" /> 7 7 <script type="text/javascript" src="../../../../ckeditor_source.js"></script> 8 8 <script type="text/javascript" src="../../test.js"></script> … … 36 36 assert.areSame( 0, $range.compareEndPoints( 'EndToEnd', $range2 ), 'EndToEnd' ); 37 37 }, 38 38 39 // Test select a image surrounded by texts. 40 test_selection_3846 : function() 41 { 42 var element = doc.getById( 'testZone' ); 43 element.setHtml( '<p>A normal image <img src="../../_assets/regular_smile.gif" id="testImage"> inside the text<\/p>' ); 44 var image = doc.getById('testImage'); 45 46 doc.getSelection().selectElement( image ); 47 var selectedElement = doc.getSelection().getSelectedElement() ; 48 assert.areSame( CKEDITOR.SELECTION_ELEMENT, doc.getSelection().getType() ); 49 assert.isNotNull( selectedElement, 'The floated image hasn\'t been selected' ); 50 assert.areSame( image.$, selectedElement.$, 'The floated image hasn\'t been selected correctly' ); 51 }, 52 53 // Test select a float image surrounded by inline style elements. 54 test_selection_3846_2 : function() 55 { 56 var element = doc.getById( 'testZone' ); 57 element.setHtml( '<p><b>some</b><span><img src="../../_assets/regular_smile.gif" align="left" id="testImage"></span><b>text</b><\/p>' ); 58 var image = doc.getById('testImage'); 59 60 doc.getSelection().selectElement( image ); 61 var selectedElement = doc.getSelection().getSelectedElement() ; 62 assert.areSame( CKEDITOR.SELECTION_ELEMENT, doc.getSelection().getType(), 'The selection type is incorrect.' ); 63 assert.isNotNull( selectedElement, 'The floated image hasn\'t been selected' ); 64 assert.areSame( image.$, selectedElement.$, 'The floated image hasn\'t been selected correctly' ); 65 }, 39 66 name : document.title 40 67 }; 41 68 })()); … … 45 72 <body> 46 73 <p> 47 74 This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">CKEditor</a>.</p> 75 <p> </p> 76 <p> </p> 77 <div id="testZone"></div> 48 78 </body> 49 79 </html> -
CHANGES.html
117 117 <li><a href="http://dev.fckeditor.net/ticket/3887">#3887</a> : Fixed an issue in which the create 118 118 list command may leak outside of a selected table cell and into the rest of document.</li> 119 119 <li><a href="http://dev.fckeditor.net/ticket/3916">#3916</a> : Fixed maximize does not enlarge editor width when width is set.</li> 120 <li><a href="http://dev.fckeditor.net/ticket/3846">#3846</a> : [Safari/Chrome]Image selection broken when surrounded with texts.</li> 120 121 </ul> 121 122 <h3> 122 123 CKEditor 3.0 RC</h3>