From 55a4ce4db2f64bd720f29c0395db2dc5fa2086c1 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe <*@iseulde.com> Date: Tue, 4 Aug 2015 05:01:11 +0000 Subject: [PATCH] TinyMCE: wptextpattern: trim whitespace Props iseulde and azaozz. Fixes #33246. Built from https://develop.svn.wordpress.org/trunk@33563 git-svn-id: http://core.svn.wordpress.org/trunk@33530 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../tinymce/plugins/wptextpattern/plugin.js | 26 ++++++++---------- .../plugins/wptextpattern/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js.gz | Bin 146847 -> 146852 bytes wp-includes/version.php | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 582b42965b..8343e632b9 100644 --- a/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -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. diff --git a/wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js b/wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js index 3972ccd736..08f990bedc 100644 --- a/wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js @@ -1 +1 @@ -!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling),b}}function e(){var e,f,g=c.selection.getRng(),i=g.startContainer;i&&d(i)===i&&(e=i.parentNode,f=i.data,a.each(l,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){i.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){h="space"}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),h=g.startOffset,k=g.startContainer,l=d(k),n=m.length;if(l){for(b=l.data;n--;)if(0===b.indexOf(m[n].start)){e=m[n];break}if(e){if(l===k){if(a.trim(b)===e.start)return;h=Math.max(0,h-e.start.length)}i=l,j=e}}}function g(){i&&(c.undoManager.add(),c.undoManager.transact(function(){c.formatter.apply(j.format,{},i),i.deleteData(0,j.start.length)}),b(function(){h="enter"})),i=null,j=null}var h,i,j,k=a.util.VK,l=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],m=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){h=null}),c.on("keydown",function(a){(h&&27===a.keyCode||"space"===h&&a.keyCode===k.BACKSPACE)&&(c.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),a.keyCode!==k.ENTER||k.modifierPressed(a)||f()},!0),c.on("keyup",function(a){k.modifierPressed(a)||(a.keyCode===k.SPACEBAR?e():a.keyCode===k.ENTER&&g())})})}(window.tinymce,window.setTimeout); \ No newline at end of file +!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling&&3===b.nextSibling.nodeType?b.nextSibling:null),b}}function e(){var e,f,g=c.selection.getRng(),i=g.startContainer;i&&d(i)===i&&(e=i.parentNode,f=i.data,a.each(l,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){i.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){h="space"}),!1}))}function f(){var b,e,f=c.selection.getRng(),g=f.startContainer,h=d(g),k=m.length;if(h){for(b=h.data;k--;)if(0===b.indexOf(m[k].start)){e=m[k];break}e&&(h!==g||a.trim(b)!==e.start)&&(i=h,j=e)}}function g(){i&&(c.undoManager.add(),c.undoManager.transact(function(){c.formatter.apply(j.format,{},i),i.replaceData(0,i.data.length,a.trim(i.data.slice(j.start.length)))}),b(function(){h="enter"})),i=null,j=null}var h,i,j,k=a.util.VK,l=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],m=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){h=null}),c.on("keydown",function(a){(h&&27===a.keyCode||"space"===h&&a.keyCode===k.BACKSPACE)&&(c.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),a.keyCode!==k.ENTER||k.modifierPressed(a)||f()},!0),c.on("keyup",function(a){k.modifierPressed(a)||(a.keyCode===k.SPACEBAR?e():a.keyCode===k.ENTER&&g())})})}(window.tinymce,window.setTimeout); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 787d6049e7099ac59558f6c5f436555b9d9ba02c..2f9a9fe073060f213effe38d754ef632427bc121 100644 GIT binary patch delta 2883 zcmV-J3%vB7`v|1_2!MnEv;u`Pf2|DFpeIFEDvL}jJ*PMl7s}LuIkn(U;)+)54aAOc z6c4)WT3|raPe#zqjDlD&U17wrqB8q*$sQL!s zD%j^W?aNbv2zP>*Vvnq}`aAkil_MIp09sAZ-m0R|`r`3D*&9AMSf2U=6YNdC-JkeTj zMWD4r1sGZZSq`(^nK*npINfX<$ZNr?16~bQp6dqNtV2-v%~t)I>0feVe?Mgj8u=rw zB-yyDUa)7Z?(hem&ht@!R4iX3)j6`+1TX@qbT~UL70u82?nm$kJU@HWLzXW07Qdc0 zMPJ0=U8>zOl;krHe?=U)pCc*D0sWwI7rIzgyK}Ql7G7OX%SRw*x+o8h6LwljY?pN5 zJ>el@6$8I1D7jR+nR1anAd(X>n`OI7)k%A6)sk6Hl5T4xEyZTfOIcsyk=)tmaHWC@ zkD}v~k^hj_kJj3mP;wp@^MpjLu^(Y^PmFNi22)i0DR2Ike@D{E4O@L~#Pxy*ZD6_k z@9@GnJwR~iZtQ~r%~sTRoG(xm;=42A0*Fq37dq`B-XyL2qq?IpXz+om;GsP16W7;q z&qSyg&6ROW2~)=^Ff8@T%A@Ior4^#88H>|3KSBPmS)3waNh7MJQTBz$kk*S`{=;gX zv&m?|3F4Kaf1=DO8hPvG2FWX(51|ghkjDTM&6EQebdSCh9E{DXWSkiZl1LURa?J}4 z>Z9(p`13|H`F9SBW^U@wKDGXf#t`7a5sq%Z4L%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