Skip to content

Commit fa1a214

Browse files
committed
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
1 parent b1446f4 commit fa1a214

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

  • src/wp-includes/js/tinymce/plugins/wptextpattern
  • tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern

src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
}
8888
}
8989

90+
if ( ! child.nodeValue ) {
91+
child = child.nextSibling;
92+
}
93+
9094
if ( child !== node ) {
9195
return;
9296
}
@@ -109,10 +113,18 @@
109113
editor.undoManager.add();
110114

111115
editor.undoManager.transact( function() {
116+
var $$parent;
117+
112118
if ( replace ) {
113119
$$( node ).replaceWith( document.createTextNode( replace ) );
114120
} else {
115-
$$( node.parentNode ).empty().append( '<br>' );
121+
$$parent = $$( node.parentNode );
122+
123+
$$( node ).remove();
124+
125+
if ( ! $$parent.html() ) {
126+
$$parent.append( '<br>' );
127+
}
116128
}
117129

118130
editor.selection.setCursorLocation( parent );

tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
}, assert.async() );
7878
} );
7979

80-
QUnit.test( 'Ordered list with content.', function( assert ) {
80+
QUnit.test( 'Ordered list with content. (1)', function( assert ) {
8181
editor.setContent( '<p><strong>test</strong></p>' );
8282
editor.selection.setCursorLocation();
8383

@@ -86,6 +86,15 @@
8686
}, assert.async() );
8787
} );
8888

89+
QUnit.test( 'Ordered list with content. (2)', function( assert ) {
90+
editor.setContent( '<p><strong>test</strong></p>' );
91+
editor.selection.setCursorLocation( editor.$( 'p' )[0], 0 );
92+
93+
type( '* ', function() {
94+
assert.equal( editor.getContent(), '<ul>\n<li><strong>test</strong></li>\n</ul>' );
95+
}, assert.async() );
96+
} );
97+
8998
QUnit.test( 'Only transform inside a P tag.', function( assert ) {
9099
editor.setContent( '<h1>test</h1>' );
91100
editor.selection.setCursorLocation();

0 commit comments

Comments
 (0)