From 4393f478eaa8646d775d8a2fbf3a66bd1fe67443 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Tue, 28 Jul 2015 11:40:29 +0000 Subject: [PATCH] TinyMCE: wptextpattern: fix typo and make it faster See #31441. git-svn-id: https://develop.svn.wordpress.org/trunk@33458 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tinymce/plugins/wptextpattern/plugin.js | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 03e2cad79c..76767d0f9f 100644 --- a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -12,8 +12,7 @@ */ ( function( tinymce, setTimeout ) { tinymce.PluginManager.add( 'wptextpattern', function( editor ) { - var $$ = editor.$, - VK = tinymce.util.VK, + var VK = tinymce.util.VK, canUndo = false, spacePatterns = [ { regExp: /^[*-]\s/, cmd: 'InsertUnorderedList' }, @@ -44,7 +43,7 @@ }, true ); editor.on( 'keyup', function( event ) { - if ( event.keyCode === VK.SPACEBAR || ! VK.modifierPressed( event ) ) { + if ( event.keyCode === VK.SPACEBAR && ! VK.modifierPressed( event ) ) { space(); } } ); @@ -79,41 +78,30 @@ function space() { var rng = editor.selection.getRng(), node = rng.startContainer, + parent, text; - if ( firstNode( node ) !== node ) { + if ( ! node || firstNode( node ) !== node ) { return; } + parent = node.parentNode; text = node.data; tinymce.each( spacePatterns, function( pattern ) { - var replace = text.replace( pattern.regExp, '' ); + var match = text.match( pattern.regExp ); - if ( text === replace ) { - return; - } - - if ( rng.startOffset !== text.length - replace.length ) { + if ( ! match || rng.startOffset !== match[0].length ) { return; } editor.undoManager.add(); editor.undoManager.transact( function() { - var parent = node.parentNode, - $$parent; + node.deleteData( 0, match[0].length ); - if ( replace ) { - $$( node ).replaceWith( document.createTextNode( replace ) ); - } else { - $$parent = $$( parent ); - - $$( node ).remove(); - - if ( ! $$parent.html() ) { - $$parent.append( '
' ); - } + if ( ! parent.innerHTML ) { + parent.appendChild( document.createElement( 'br' ) ); } editor.selection.setCursorLocation( parent );