Skip to content

Commit

Permalink
Fix all ranges, on all browsers and do this only if hiddenSelCon real…
Browse files Browse the repository at this point in the history
…ly exists.
  • Loading branch information
Reinmar authored and oleq committed Jan 10, 2014
1 parent 653f802 commit f905c2d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/selection.js
Expand Up @@ -399,6 +399,15 @@
}
}

// Fix ranges which ends after hidden selection container.
function fixRangesAfterHiddenSelectionContainer( ranges, root, hiddenSelectionContainerIndex ) {
for ( var i = 0; i < ranges.length; ++i ) {
range = ranges[ i ];
if ( range.endContainer.equals( root ) )
range.endOffset = Math.min( range.endOffset, hiddenSelectionContainerIndex );
}
}

// Setup all editor instances for the necessary selection hooks.
CKEDITOR.on( 'instanceCreated', function( ev ) {
var editor = ev.editor;
Expand Down Expand Up @@ -1716,15 +1725,14 @@
*/
selectRanges: function( ranges ) {
var editor = this.root.editor,
hiddenSelectionContainer,
hiddenSelectionContainerIndex;
hiddenSelectionContainer;

// Check if there's a hiddenSelectionContainer in editable at some index.
// Some ranges may be anchored after the hiddenSelectionContainer and,
// once the container is removed while resetting the selection, they
// may need new endOffset (one element less within the range) (#11021).
if ( editor && ( hiddenSelectionContainer = editor._.hiddenSelectionContainer ) )
hiddenSelectionContainerIndex = hiddenSelectionContainer.getIndex();
fixRangesAfterHiddenSelectionContainer( ranges, this.root, hiddenSelectionContainer.getIndex() );

this.reset();

Expand Down Expand Up @@ -1908,11 +1916,6 @@

range = ranges[ i ];

// Fix the endOffset of the range if it is set after the
// hiddenSelectionContainer, which is no longer in DOM now (#11021).
if ( range.endContainer.equals( this.root ) )
range.endOffset = Math.min( range.endOffset, hiddenSelectionContainerIndex );

var nativeRange = this.document.$.createRange();
var startContainer = range.startContainer;

Expand Down

0 comments on commit f905c2d

Please sign in to comment.