From 662355f30cf205f095285e496fea7ea25db19972 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Wed, 29 Jul 2015 23:11:42 +0000 Subject: [PATCH] TinyMCE: wptextpattern: undo on esc after enter See #31441. git-svn-id: https://develop.svn.wordpress.org/trunk@33508 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wptextpattern/plugin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 23a41674a0..291264768a 100644 --- a/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -13,7 +13,6 @@ ( function( tinymce, setTimeout ) { tinymce.PluginManager.add( 'wptextpattern', function( editor ) { var VK = tinymce.util.VK, - canUndo = false, spacePatterns = [ { regExp: /^[*-]\s/, cmd: 'InsertUnorderedList' }, { regExp: /^1[.)]\s/, cmd: 'InsertOrderedList' } @@ -26,14 +25,14 @@ { start: '######', format: 'h6' }, { start: '>', format: 'blockquote' } ], - refNode, refPattern; + canUndo, refNode, refPattern; editor.on( 'selectionchange', function() { - canUndo = false; + canUndo = null; } ); editor.on( 'keydown', function( event ) { - if ( canUndo && ( event.keyCode === VK.BACKSPACE || event.keyCode === 27 /* ESCAPE */ ) ) { + if ( ( canUndo && event.keyCode === 27 /* ESCAPE */ ) || ( canUndo === 'space' && event.keyCode === VK.BACKSPACE ) ) { editor.undoManager.undo(); event.preventDefault(); } @@ -115,7 +114,7 @@ // We need to wait for native events to be triggered. setTimeout( function() { - canUndo = true; + canUndo = 'space'; } ); return false; @@ -168,6 +167,11 @@ editor.formatter.apply( refPattern.format, {}, refNode ); refNode.deleteData( 0, refPattern.start.length ); } ); + + // We need to wait for native events to be triggered. + setTimeout( function() { + canUndo = 'enter'; + } ); } refNode = null;