/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
// inside a selection. We don't want to capture that.\r
body.on( 'mousedown', disableSave );\r
body.on( 'mouseup',\r
- function( evt )\r
+ function()\r
{\r
- // IE context-menu event in table cells collapse\r
- // whatever selection is, avoiding saving this\r
- // 'wrong' snapshot.(#3001)\r
- evt = evt.data;\r
- if ( evt.$.button == 2 && evt.getTarget().hasAscendant( 'table' ) )\r
- return;\r
-\r
saveEnabled = true;\r
setTimeout( function()\r
{\r
testRange = range.duplicate();\r
\r
testRange.moveToElementText( child );\r
- testRange.collapse();\r
\r
- var comparison = testRange.compareEndPoints( 'StartToStart', range );\r
+ var comparisonStart = testRange.compareEndPoints( 'StartToStart', range ),\r
+ comparisonEnd = testRange.compareEndPoints( 'EndToStart', range );\r
\r
- if ( comparison > 0 )\r
+ testRange.collapse();\r
+\r
+ if ( comparisonStart > 0 )\r
break;\r
- else if ( comparison === 0 )\r
- return {\r
- container : parent,\r
- offset : i\r
- };\r
+ // When selection stay at the side of certain self-closing elements, e.g. BR,\r
+ // our comparison will never shows an equality. (#4824)\r
+ else if ( !comparisonStart\r
+ || comparisonEnd == 1 && comparisonStart == -1 )\r
+ return { container : parent, offset : i };\r
+ else if ( !comparisonEnd )\r
+ return { container : parent, offset : i + 1 };\r
\r
testRange = null;\r
}\r
// breaking character counting logic below. (#3949)\r
var distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;\r
\r
- while ( distance > 0 )\r
- distance -= siblings[ --i ].nodeValue.length;\r
+ try\r
+ {\r
+ while ( distance > 0 )\r
+ distance -= siblings[ --i ].nodeValue.length;\r
+ }\r
+ // Measurement in IE could be somtimes wrong because of <select> element. (#4611)\r
+ catch( e )\r
+ {\r
+ distance = 0;\r
+ }\r
+\r
\r
if ( distance === 0 )\r
{\r
// Decrease the range content to exclude particial\r
// selected node on the start which doesn't have\r
// visual impact. ( #3231 )\r
- while( true )\r
+ while ( true )\r
{\r
var startContainer = range.startContainer,\r
startOffset = range.startOffset;\r
return this;\r
},\r
\r
+ getCommonAncestor : function()\r
+ {\r
+ var ranges = this.getRanges(),\r
+ startNode = ranges[ 0 ].startContainer,\r
+ endNode = ranges[ ranges.length - 1 ].endContainer;\r
+ return startNode.getCommonAncestor( endNode );\r
+ },\r
+\r
// Moving scroll bar to the current selection's start position.\r
scrollIntoView : function()\r
{\r