diff --git a/src/wp-admin/js/editor.js b/src/wp-admin/js/editor.js index a9caaa1d5d..0e47b3e022 100644 --- a/src/wp-admin/js/editor.js +++ b/src/wp-admin/js/editor.js @@ -508,47 +508,26 @@ window.wp = window.wp || {}; scrollVisualModeToStartElement( editor, startNode ); - removeSelectionMarker( editor, startNode ); - removeSelectionMarker( editor, endNode ); + removeSelectionMarker( startNode ); + removeSelectionMarker( endNode ); } /** - * @summary Remove selection marker with optional `
` parent. + * @summary Remove selection marker and the parent node if it is an empty paragraph. * - * By default TinyMCE puts every inline node at the main level in a `
` wrapping tag. + * By default TinyMCE wraps loose inline tags in a `
`. + * When removing selection markers an empty `
` may be left behind, remove it. * - * In the case with selection markers, when removed they leave an empty `
` behind, - * which adds an empty paragraph line with ` ` when switched to Text mode. - * - * In order to prevent that the wrapping `
` needs to be removed when removing the - * selection marker. - * - * @param {object} editor The TinyMCE Editor instance - * @param {object} marker The marker to be removed from the editor DOM + * @param {object} $marker The marker to be removed from the editor DOM, wrapped in an instnce of `editor.$` */ - function removeSelectionMarker( editor, marker ) { - var markerParent = editor.$( marker ).parent(); + function removeSelectionMarker( $marker ) { + var $markerParent = $marker.parent(); - if ( - ! markerParent.length || - markerParent.prop('tagName').toLowerCase() !== 'p' || - markerParent[0].childNodes.length > 1 || - ! markerParent.prop('outerHTML').match(/^
/) - ) { - /** - * The selection marker is not self-contained in a
. - * In this case only the selection marker is removed, since - * it will affect the content. - */ - marker.remove(); - } - else { - /** - * The marker is self-contained in an blank `
` tag. - * - * This is usually inserted by TinyMCE - */ - markerParent.remove(); + $marker.remove(); + + //Remove empty paragraph left over after removing the marker. + if ( $markerParent.is( 'p' ) && ! $markerParent.children().length && ! $markerParent.text() ) { + $markerParent.remove(); } }