Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 't/11042'
  • Loading branch information
Reinmar committed Dec 3, 2013
2 parents 6aca6fe + bc7a60b commit eaa4592
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -19,6 +19,7 @@ Fixed Issues:
* [#10890](http://dev.ckeditor.com/ticket/10890): Fixed: Error thrown when pressing *Delete* key in a list item.
* [#10055](http://dev.ckeditor.com/ticket/10055): [IE8-10] Fixed: *Delete* pressed on selected image causes browser to go back.
* [#11183](http://dev.ckeditor.com/ticket/11183): Fixed: Inserting line or table in multiple rows selection causes browser crash. Additionally, the [`editor.insertElement`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertElement) method does not insert element into every range of a selection any more.
* [#11042](http://dev.ckeditor.com/ticket/11042): Fixed: Selection made on element containing non-editable element was not auto faked.


## CKEditor 4.3
Expand Down
36 changes: 29 additions & 7 deletions core/selection.js
Expand Up @@ -378,6 +378,31 @@
};
}

// If fake selection should be applied this function will return instance of
// CKEDITOR.dom.element which should gain fake selection.
function getNonEditableFakeSelectionReceiver( ranges ) {
var enclosedNode,
shrinkedNode,
clone,
range;

if ( ranges.length == 1 && !( range = ranges[ 0 ] ).collapsed &&
( enclosedNode = range.getEnclosedNode() ) && enclosedNode.type == CKEDITOR.NODE_ELEMENT ) {
// So far we can't say that enclosed element is non-editable. Before checking,
// we'll shrink range (clone). Shrinking will stop on non-editable range, or
// innermost element (#11114).
clone = range.clone();
clone.shrink( CKEDITOR.SHRINK_ELEMENT, true );

// If shrinked range still encloses an element, check this one (shrink stops only on non-editable elements).
if ( ( shrinkedNode = clone.getEnclosedNode() ) && shrinkedNode.type == CKEDITOR.NODE_ELEMENT )
enclosedNode = shrinkedNode;

if ( enclosedNode.getAttribute( 'contenteditable' ) == 'false' )
return enclosedNode;
}
}

// Setup all editor instances for the necessary selection hooks.
CKEDITOR.on( 'instanceCreated', function( ev ) {
var editor = ev.editor;
Expand Down Expand Up @@ -1713,13 +1738,10 @@
}

// Handle special case - automatic fake selection on non-editable elements.
var enclosedNode;
if (
ranges.length == 1 && !ranges[ 0 ].collapsed &&
( enclosedNode = ranges[ 0 ].getEnclosedNode() ) &&
enclosedNode.type == CKEDITOR.NODE_ELEMENT && enclosedNode.getAttribute( 'contenteditable' ) == 'false'
) {
this.fake( enclosedNode );
var receiver = getNonEditableFakeSelectionReceiver( ranges );

if ( receiver ) {
this.fake( receiver );
return;
}

Expand Down

0 comments on commit eaa4592

Please sign in to comment.