Editor: Use editor.$ to improve removeSelectionMarker().

See #42029
Built from https://develop.svn.wordpress.org/trunk@41656


git-svn-id: http://core.svn.wordpress.org/trunk@41490 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2017-10-01 10:33:47 +00:00
parent 5335ba8c20
commit 40d84f7503
3 changed files with 15 additions and 36 deletions

View File

@ -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 `<p>` 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 `<p>` wrapping tag.
* By default TinyMCE wraps loose inline tags in a `<p>`.
* When removing selection markers an empty `<p>` may be left behind, remove it.
*
* In the case with selection markers, when removed they leave an empty `<p>` behind,
* which adds an empty paragraph line with `&nbsp;` when switched to Text mode.
*
* In order to prevent that the wrapping `<p>` 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(/^<p>/)
) {
/**
* The selection marker is not self-contained in a <p>.
* 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 `<p>` 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();
}
}

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41655';
$wp_version = '4.9-alpha-41656';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.