TinyMCE: wptextpattern: fix issue that removes content

* If the resulting text node is empty, don't remove all the content from the paragraph.
* If there's an empty text node at the start of the paragraph, ignore it and consider the next node to be the start.

See #31441.


git-svn-id: https://develop.svn.wordpress.org/trunk@32832 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-06-18 11:33:11 +00:00
parent b1446f4221
commit fa1a214eb6
2 changed files with 23 additions and 2 deletions

View File

@ -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 );

View File

@ -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();