TinyMCE: wptextpattern: trim whitespace

Props iseulde and azaozz.
Fixes #33246.


git-svn-id: https://develop.svn.wordpress.org/trunk@33563 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-08-03 22:06:25 +00:00
parent e30bd2f439
commit aaf15cdde8
2 changed files with 13 additions and 14 deletions

View File

@ -53,7 +53,7 @@
}
} );
function firstNode( node ) {
function firstTextNode( node ) {
var parent = editor.dom.getParent( node, 'p' ),
child;
@ -74,7 +74,11 @@
}
if ( ! child.data ) {
child = child.nextSibling;
if ( child.nextSibling && child.nextSibling.nodeType === 3 ) {
child = child.nextSibling;
} else {
child = null;
}
}
return child;
@ -86,7 +90,7 @@
parent,
text;
if ( ! node || firstNode( node ) !== node ) {
if ( ! node || firstTextNode( node ) !== node ) {
return;
}
@ -123,11 +127,9 @@
}
function watchEnter() {
var selection = editor.selection,
rng = selection.getRng(),
offset = rng.startOffset,
var rng = editor.selection.getRng(),
start = rng.startContainer,
node = firstNode( start ),
node = firstTextNode( start ),
i = enterPatterns.length,
text, pattern;
@ -148,12 +150,8 @@
return;
}
if ( node === start ) {
if ( tinymce.trim( text ) === pattern.start ) {
return;
}
offset = Math.max( 0, offset - pattern.start.length );
if ( node === start && tinymce.trim( text ) === pattern.start ) {
return;
}
refNode = node;
@ -166,7 +164,7 @@
editor.undoManager.transact( function() {
editor.formatter.apply( refPattern.format, {}, refNode );
refNode.deleteData( 0, refPattern.start.length );
refNode.replaceData( 0, refNode.data.length, tinymce.trim( refNode.data.slice( refPattern.start.length ) ) );
} );
// We need to wait for native events to be triggered.

View File

@ -150,6 +150,7 @@
editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 8 );
type( '\n', function() {
assert.equal( editor.$( 'h3' )[0].firstChild.data, 'test' );
assert.equal( editor.getContent(), '<h3>test</h3>\n<p>&nbsp;</p>' );
}, assert.async() );
} );