X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fselection%2Fplugin.js;h=85981fa078aff2329c200fd4da6770bdf3f1811a;hp=a78bb36f8dc040eb180dab36e3fdfb3188cb66ec;hb=c6e377a02b54abc07129d72b632763c727476a15;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6 diff --git a/_source/plugins/selection/plugin.js b/_source/plugins/selection/plugin.js index a78bb36..85981fa 100644 --- a/_source/plugins/selection/plugin.js +++ b/_source/plugins/selection/plugin.js @@ -459,17 +459,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license testRange = range.duplicate(); testRange.moveToElementText( child ); - testRange.collapse(); - var comparison = testRange.compareEndPoints( 'StartToStart', range ); + var comparisonStart = testRange.compareEndPoints( 'StartToStart', range ), + comparisonEnd = testRange.compareEndPoints( 'EndToStart', range ); + + testRange.collapse(); - if ( comparison > 0 ) + if ( comparisonStart > 0 ) break; - else if ( comparison === 0 ) - return { - container : parent, - offset : i - }; + // When selection stay at the side of certain self-closing elements, e.g. BR, + // our comparison will never shows an equality. (#4824) + else if ( !comparisonStart + || comparisonEnd == 1 && comparisonStart == -1 ) + return { container : parent, offset : i }; + else if ( !comparisonEnd ) + return { container : parent, offset : i + 1 }; testRange = null; } @@ -488,8 +492,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // breaking character counting logic below. (#3949) var distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length; - while ( distance > 0 ) - distance -= siblings[ --i ].nodeValue.length; + try + { + while ( distance > 0 ) + distance -= siblings[ --i ].nodeValue.length; + } + // Measurement in IE could be somtimes wrong because of