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:
parent
e30bd2f439
commit
aaf15cdde8
@ -53,7 +53,7 @@
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
function firstNode( node ) {
|
function firstTextNode( node ) {
|
||||||
var parent = editor.dom.getParent( node, 'p' ),
|
var parent = editor.dom.getParent( node, 'p' ),
|
||||||
child;
|
child;
|
||||||
|
|
||||||
@ -74,7 +74,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! child.data ) {
|
if ( ! child.data ) {
|
||||||
child = child.nextSibling;
|
if ( child.nextSibling && child.nextSibling.nodeType === 3 ) {
|
||||||
|
child = child.nextSibling;
|
||||||
|
} else {
|
||||||
|
child = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
@ -86,7 +90,7 @@
|
|||||||
parent,
|
parent,
|
||||||
text;
|
text;
|
||||||
|
|
||||||
if ( ! node || firstNode( node ) !== node ) {
|
if ( ! node || firstTextNode( node ) !== node ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,11 +127,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function watchEnter() {
|
function watchEnter() {
|
||||||
var selection = editor.selection,
|
var rng = editor.selection.getRng(),
|
||||||
rng = selection.getRng(),
|
|
||||||
offset = rng.startOffset,
|
|
||||||
start = rng.startContainer,
|
start = rng.startContainer,
|
||||||
node = firstNode( start ),
|
node = firstTextNode( start ),
|
||||||
i = enterPatterns.length,
|
i = enterPatterns.length,
|
||||||
text, pattern;
|
text, pattern;
|
||||||
|
|
||||||
@ -148,12 +150,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node === start ) {
|
if ( node === start && tinymce.trim( text ) === pattern.start ) {
|
||||||
if ( tinymce.trim( text ) === pattern.start ) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = Math.max( 0, offset - pattern.start.length );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refNode = node;
|
refNode = node;
|
||||||
@ -166,7 +164,7 @@
|
|||||||
|
|
||||||
editor.undoManager.transact( function() {
|
editor.undoManager.transact( function() {
|
||||||
editor.formatter.apply( refPattern.format, {}, refNode );
|
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.
|
// We need to wait for native events to be triggered.
|
||||||
|
@ -150,6 +150,7 @@
|
|||||||
editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 8 );
|
editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 8 );
|
||||||
|
|
||||||
type( '\n', function() {
|
type( '\n', function() {
|
||||||
|
assert.equal( editor.$( 'h3' )[0].firstChild.data, 'test' );
|
||||||
assert.equal( editor.getContent(), '<h3>test</h3>\n<p> </p>' );
|
assert.equal( editor.getContent(), '<h3>test</h3>\n<p> </p>' );
|
||||||
}, assert.async() );
|
}, assert.async() );
|
||||||
} );
|
} );
|
||||||
|
Loading…
Reference in New Issue
Block a user