Make WordPress Core

Ticket #31441: 31441.19.patch

File 31441.19.patch, 2.7 KB (added by azaozz, 10 years ago)
  • src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

     
    1414        tinymce.PluginManager.add( 'wptextpattern', function( editor ) {
    1515                var $$ = editor.$,
    1616                        patterns = [],
     17                        VK = tinymce.util.VK,
    1718                        canUndo = false;
    1819
    1920                /**
     
    5253                } );
    5354
    5455                editor.on( 'keydown', function( event ) {
    55                         if ( canUndo && event.keyCode === tinymce.util.VK.BACKSPACE ) {
     56                        if ( canUndo && ( event.keyCode === VK.BACKSPACE || event.keyCode === 27 ) ) { // esc
    5657                                editor.undoManager.undo();
    5758                                event.preventDefault();
    5859                        }
     
    6162                editor.on( 'keyup', function( event ) {
    6263                        var rng, node, text, parent, child;
    6364
    64                         if ( event.keyCode !== tinymce.util.VK.SPACEBAR ) {
     65                        if ( event.keyCode !== VK.SPACEBAR ) {
    6566                                return;
    6667                        }
    6768
     
    8788                                }
    8889                        }
    8990
     91                        if ( ! child.nodeValue ) {
     92                                child = child.nextSibling;
     93                        }
     94
    9095                        if ( child !== node ) {
    9196                                return;
    9297                        }
     
    109114                                editor.undoManager.add();
    110115
    111116                                editor.undoManager.transact( function() {
     117                                        var $$parent;
     118
    112119                                        if ( replace ) {
    113120                                                $$( node ).replaceWith( document.createTextNode( replace ) );
    114121                                        } else  {
    115                                                 $$( node.parentNode ).empty().append( '<br>' );
     122                                                $$parent = $$( node.parentNode );
     123
     124                                                $$( node ).remove();
     125
     126                                                if ( ! $$parent.html() ) {
     127                                                        $$parent.append( '<br>' );
     128                                                }
    116129                                        }
    117130
    118131                                        editor.selection.setCursorLocation( parent );
  • tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

     
    7777                }, assert.async() );
    7878        } );
    7979
    80         QUnit.test( 'Ordered list with content.', function( assert ) {
     80        QUnit.test( 'Ordered list with content. (1)', function( assert ) {
    8181                editor.setContent( '<p><strong>test</strong></p>' );
    8282                editor.selection.setCursorLocation();
    8383
     
    8686                }, assert.async() );
    8787        } );
    8888
     89        QUnit.test( 'Ordered list with content. (2)', function( assert ) {
     90                editor.setContent( '<p><strong>test</strong></p>' );
     91                editor.selection.setCursorLocation( editor.$( 'p' )[0], 0 );
     92
     93                type( '* ', function() {
     94                        assert.equal( editor.getContent(), '<ul>\n<li><strong>test</strong></li>\n</ul>' );
     95                }, assert.async() );
     96        } );
     97
    8998        QUnit.test( 'Only transform inside a P tag.', function( assert ) {
    9099                editor.setContent( '<h1>test</h1>' );
    91100                editor.selection.setCursorLocation();