TinyMCE: wptextpattern: undo on esc after enter

See #31441.


git-svn-id: https://develop.svn.wordpress.org/trunk@33508 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-07-29 23:11:42 +00:00
parent 976687bc59
commit 662355f30c

View File

@ -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;