TinyMCE: wptextpattern: reorder undo

After formatting on enter, undo should undo the formatting first, then undo the new line.

See #31441.


git-svn-id: https://develop.svn.wordpress.org/trunk@33507 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-07-29 22:48:02 +00:00
parent 1768c8c85a
commit 976687bc59

View File

@ -25,7 +25,8 @@
{ start: '#####', format: 'h5' }, { start: '#####', format: 'h5' },
{ start: '######', format: 'h6' }, { start: '######', format: 'h6' },
{ start: '>', format: 'blockquote' } { start: '>', format: 'blockquote' }
]; ],
refNode, refPattern;
editor.on( 'selectionchange', function() { editor.on( 'selectionchange', function() {
canUndo = false; canUndo = false;
@ -38,13 +39,17 @@
} }
if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) { if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {
enter(); watchEnter();
} }
}, true ); }, true );
editor.on( 'keyup', function( event ) { editor.on( 'keyup', function( event ) {
if ( event.keyCode === VK.SPACEBAR && ! VK.modifierPressed( event ) ) { if ( ! VK.modifierPressed( event ) ) {
space(); if ( event.keyCode === VK.SPACEBAR ) {
space();
} else if ( event.keyCode === VK.ENTER ) {
enter();
}
} }
} ); } );
@ -117,7 +122,7 @@
} ); } );
} }
function enter() { function watchEnter() {
var selection = editor.selection, var selection = editor.selection,
rng = selection.getRng(), rng = selection.getRng(),
offset = rng.startOffset, offset = rng.startOffset,
@ -151,17 +156,22 @@
offset = Math.max( 0, offset - pattern.start.length ); offset = Math.max( 0, offset - pattern.start.length );
} }
editor.undoManager.add(); refNode = node;
refPattern = pattern;
}
editor.undoManager.transact( function() { function enter() {
node.deleteData( 0, pattern.start.length ); if ( refNode ) {
editor.undoManager.add();
editor.formatter.apply( pattern.format, {}, start ); editor.undoManager.transact( function() {
editor.formatter.apply( refPattern.format, {}, refNode );
refNode.deleteData( 0, refPattern.start.length );
} );
}
rng.setStart( start, offset ); refNode = null;
rng.collapse( true ); refPattern = null;
selection.setRng( rng );
} );
} }
} ); } );
} )( window.tinymce, window.setTimeout ); } )( window.tinymce, window.setTimeout );