Skip to content
Permalink
Browse files

Fix all ranges, on all browsers and do this only if hiddenSelCon real…

…ly exists.
  • Loading branch information...
Reinmar authored and oleq committed Jan 10, 2014
1 parent 653f802 commit f905c2d358695fa3bca1b9f57fcfd9e9b001d0d6
Showing with 11 additions and 8 deletions.
  1. +11 −8 core/selection.js
@@ -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;
@@ -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();

@@ -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;

0 comments on commit f905c2d

Please sign in to comment.
You can’t perform that action at this time.