Make WordPress Core

Changeset 33507


Ignore:
Timestamp:
07/29/2015 10:48:02 PM (10 years ago)
Author:
iseulde
Message:

TinyMCE: wptextpattern: reorder undo

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

See #31441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

    r33458 r33507  
    2626                { start: '######', format: 'h6' },
    2727                { start: '>', format: 'blockquote' }
    28             ];
     28            ],
     29            refNode, refPattern;
    2930
    3031        editor.on( 'selectionchange', function() {
     
    3940
    4041            if ( event.keyCode === VK.ENTER && ! VK.modifierPressed( event ) ) {
    41                 enter();
     42                watchEnter();
    4243            }
    4344        }, true );
    4445
    4546        editor.on( 'keyup', function( event ) {
    46             if ( event.keyCode === VK.SPACEBAR && ! VK.modifierPressed( event ) ) {
    47                 space();
     47            if ( ! VK.modifierPressed( event ) ) {
     48                if ( event.keyCode === VK.SPACEBAR ) {
     49                    space();
     50                } else if ( event.keyCode === VK.ENTER ) {
     51                    enter();
     52                }
    4853            }
    4954        } );
     
    118123        }
    119124
    120         function enter() {
     125        function watchEnter() {
    121126            var selection = editor.selection,
    122127                rng = selection.getRng(),
     
    152157            }
    153158
    154             editor.undoManager.add();
     159            refNode = node;
     160            refPattern = pattern;
     161        }
    155162
    156             editor.undoManager.transact( function() {
    157                 node.deleteData( 0, pattern.start.length );
     163        function enter() {
     164            if ( refNode ) {
     165                editor.undoManager.add();
    158166
    159                 editor.formatter.apply( pattern.format, {}, start );
     167                editor.undoManager.transact( function() {
     168                    editor.formatter.apply( refPattern.format, {}, refNode );
     169                    refNode.deleteData( 0, refPattern.start.length );
     170                } );
     171            }
    160172
    161                 rng.setStart( start, offset );
    162                 rng.collapse( true );
    163                 selection.setRng( rng );
    164             } );
     173            refNode = null;
     174            refPattern = null;
    165175        }
    166176    } );
Note: See TracChangeset for help on using the changeset viewer.