diff --git a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js index 0366c28544..4a81ca9ef8 100644 --- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js @@ -963,22 +963,28 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { if ( node.nodeName === 'IMG' ) { wrap = editor.dom.getParent( node, '.mceTemp' ); + + if ( ! wrap && node.parentNode.nodeName === 'A' && ! hasTextContent( node.parentNode ) ) { + wrap = node.parentNode; + } } } ); editor.on( 'drop', function( event ) { - var rng; + var dom = editor.dom, + rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() ); - if ( wrap && ( rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() ) ) ) { + // Don't allow anything to be dropped in a captioned image. + if ( dom.getParent( rng.startContainer, '.mceTemp' ) ) { + event.preventDefault(); + } else if ( wrap ) { event.preventDefault(); - if ( ! editor.dom.getParent( rng.startContainer, '.mceTemp' ) ) { - editor.undoManager.transact( function() { - editor.selection.setRng( rng ); - editor.selection.setNode( wrap ); - editor.dom.remove( wrap ); - } ); - } + editor.undoManager.transact( function() { + editor.selection.setRng( rng ); + editor.selection.setNode( wrap ); + dom.remove( wrap ); + } ); } wrap = null;