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.

Built from https://develop.svn.wordpress.org/trunk@32832


git-svn-id: http://core.svn.wordpress.org/trunk@32803 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ella Iseulde Van Dorpe 2015-06-18 11:34:25 +00:00
parent 1c586b9390
commit 8b6ff40038
4 changed files with 15 additions and 3 deletions

View File

@ -87,6 +87,10 @@
} }
} }
if ( ! child.nodeValue ) {
child = child.nextSibling;
}
if ( child !== node ) { if ( child !== node ) {
return; return;
} }
@ -109,10 +113,18 @@
editor.undoManager.add(); editor.undoManager.add();
editor.undoManager.transact( function() { editor.undoManager.transact( function() {
var $$parent;
if ( replace ) { if ( replace ) {
$$( node ).replaceWith( document.createTextNode( replace ) ); $$( node ).replaceWith( document.createTextNode( replace ) );
} else { } else {
$$( node.parentNode ).empty().append( '<br>' ); $$parent = $$( node.parentNode );
$$( node ).remove();
if ( ! $$parent.html() ) {
$$parent.append( '<br>' );
}
} }
editor.selection.setCursorLocation( parent ); editor.selection.setCursorLocation( parent );

View File

@ -1 +1 @@
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a,b){f.push({regExp:a,callback:b})}var e=c.$,f=[],g=!1;d(/^[*-]\s/,function(){this.execCommand("InsertUnorderedList")}),d(/^1[.)]\s/,function(){this.execCommand("InsertOrderedList")}),d(/^>\s/,function(){this.formatter.toggle("blockquote")}),d(/^(#{2,6})\s/,function(){this.formatter.toggle("h"+arguments[1].length)}),c.on("selectionchange",function(){g=!1}),c.on("keydown",function(b){g&&b.keyCode===a.util.VK.BACKSPACE&&(c.undoManager.undo(),b.preventDefault())}),c.on("keyup",function(d){var h,i,j,k,l;if(d.keyCode===a.util.VK.SPACEBAR&&(h=c.selection.getRng(),i=h.startContainer,i&&3===i.nodeType&&(j=i.nodeValue,k=c.dom.getParent(i,"p")))){for(;(l=k.firstChild)&&3!==l.nodeType;)k=l;l===i&&a.each(f,function(a){var d,f=j.replace(a.regExp,function(){return d=arguments,""});if(j!==f&&h.startOffset===j.length-f.length)return c.undoManager.add(),c.undoManager.transact(function(){f?e(i).replaceWith(document.createTextNode(f)):e(i.parentNode).empty().append("<br>"),c.selection.setCursorLocation(k),a.callback.apply(c,d)}),b(function(){g=!0}),!1})}})})}(window.tinymce,window.setTimeout); !function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a,b){f.push({regExp:a,callback:b})}var e=c.$,f=[],g=!1;d(/^[*-]\s/,function(){this.execCommand("InsertUnorderedList")}),d(/^1[.)]\s/,function(){this.execCommand("InsertOrderedList")}),d(/^>\s/,function(){this.formatter.toggle("blockquote")}),d(/^(#{2,6})\s/,function(){this.formatter.toggle("h"+arguments[1].length)}),c.on("selectionchange",function(){g=!1}),c.on("keydown",function(b){g&&b.keyCode===a.util.VK.BACKSPACE&&(c.undoManager.undo(),b.preventDefault())}),c.on("keyup",function(d){var h,i,j,k,l;if(d.keyCode===a.util.VK.SPACEBAR&&(h=c.selection.getRng(),i=h.startContainer,i&&3===i.nodeType&&(j=i.nodeValue,k=c.dom.getParent(i,"p")))){for(;(l=k.firstChild)&&3!==l.nodeType;)k=l;l.nodeValue||(l=l.nextSibling),l===i&&a.each(f,function(a){var d,f=j.replace(a.regExp,function(){return d=arguments,""});if(j!==f&&h.startOffset===j.length-f.length)return c.undoManager.add(),c.undoManager.transact(function(){var b;f?e(i).replaceWith(document.createTextNode(f)):(b=e(i.parentNode),e(i).remove(),b.html()||b.append("<br>")),c.selection.setCursorLocation(k),a.callback.apply(c,d)}),b(function(){g=!0}),!1})}})})}(window.tinymce,window.setTimeout);

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32831'; $wp_version = '4.3-alpha-32832';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.