From a0692f959781f8e98f72646a84d0e46b5bda704e Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 1 Oct 2017 10:32:58 +0000 Subject: [PATCH] Editor: Use `editor.$` to improve `removeSelectionMarker()`. See #42029 git-svn-id: https://develop.svn.wordpress.org/trunk@41656 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/editor.js | 47 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) 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(); } }