diff --git a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 7fac83774b..f1962a248a 100644 --- a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -87,6 +87,10 @@ } } + if ( ! child.nodeValue ) { + child = child.nextSibling; + } + if ( child !== node ) { return; } @@ -109,10 +113,18 @@ editor.undoManager.add(); editor.undoManager.transact( function() { + var $$parent; + if ( replace ) { $$( node ).replaceWith( document.createTextNode( replace ) ); } else { - $$( node.parentNode ).empty().append( '<br>' ); + $$parent = $$( node.parentNode ); + + $$( node ).remove(); + + if ( ! $$parent.html() ) { + $$parent.append( '<br>' ); + } } editor.selection.setCursorLocation( parent ); diff --git a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index c700676a07..0c84e7b823 100644 --- a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -77,7 +77,7 @@ }, assert.async() ); } ); - QUnit.test( 'Ordered list with content.', function( assert ) { + QUnit.test( 'Ordered list with content. (1)', function( assert ) { editor.setContent( '<p><strong>test</strong></p>' ); editor.selection.setCursorLocation(); @@ -86,6 +86,15 @@ }, assert.async() ); } ); + QUnit.test( 'Ordered list with content. (2)', function( assert ) { + editor.setContent( '<p><strong>test</strong></p>' ); + editor.selection.setCursorLocation( editor.$( 'p' )[0], 0 ); + + type( '* ', function() { + assert.equal( editor.getContent(), '<ul>\n<li><strong>test</strong></li>\n</ul>' ); + }, assert.async() ); + } ); + QUnit.test( 'Only transform inside a P tag.', function( assert ) { editor.setContent( '<h1>test</h1>' ); editor.selection.setCursorLocation();