diff --git a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
index 4df7baf875..25d3356265 100644
--- a/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
+++ b/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
@@ -181,16 +181,10 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
return content.replace( /(?:
]+mceTemp[^>]+>)?\s*(
]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g, function( all, dl ) {
var out = '';
- if ( dl.indexOf(']+>([\s\S]+?)<\/dd>/i );
-
- if ( out && out[1] ) {
- return '' + out[1] + '
';
- }
-
- return '';
+ if ( dl.indexOf('') !== -1 ) {
+ // Broken caption. The user managed to drag the image out or type in the wrapper div?
+ // Remove the , - and
- and return the remaining text.
+ return dl.replace( /]+)?>/g, '' ).replace( /<\/d[ldt]>/g, '' );
}
out = dl.replace( /\s*
]+)>\s*- ]+>([\s\S]+?)<\/dt>\s*
- ]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
@@ -896,26 +890,34 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
cmd = event.command,
dom = editor.dom;
- if ( cmd === 'mceInsertContent' ) {
+ if ( cmd === 'mceInsertContent' || cmd === 'Indent' || cmd === 'Outdent' ) {
node = editor.selection.getNode();
captionParent = dom.getParent( node, 'div.mceTemp' );
if ( captionParent ) {
- if ( pasteInCaption ) {
- pasteInCaption = false;
- // We are in the caption element, and in 'paste' context,
- // and the pasted HTML was cleaned up on 'pastePostProcess' above.
- // Let it be pasted in the caption.
- return;
- }
+ if ( cmd === 'mceInsertContent' ) {
+ if ( pasteInCaption ) {
+ pasteInCaption = false;
+ // We are in the caption element, and in 'paste' context,
+ // and the pasted HTML was cleaned up on 'pastePostProcess' above.
+ // Let it be pasted in the caption.
+ return;
+ }
- // The paste is somewhere else in the caption DL element.
- // Prevent pasting in there as it will break the caption.
- // Make new paragraph under the caption DL and move the caret there.
- p = dom.create( 'p' );
- dom.insertAfter( p, captionParent );
- editor.selection.setCursorLocation( p, 0 );
- editor.nodeChanged();
+ // The paste is somewhere else in the caption DL element.
+ // Prevent pasting in there as it will break the caption.
+ // Make new paragraph under the caption DL and move the caret there.
+ p = dom.create( 'p' );
+ dom.insertAfter( p, captionParent );
+ editor.selection.setCursorLocation( p, 0 );
+ editor.nodeChanged();
+ } else {
+ // Clicking Indent or Outdent while an image with a caption is selected breaks the caption.
+ // See #38313.
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return false;
+ }
}
} else if ( cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'wpAlignNone' ) {
node = editor.selection.getNode();