Make WordPress Core

Changeset 45631


Ignore:
Timestamp:
07/12/2019 03:24:20 AM (7 years ago)
Author:
azaozz
Message:

TinyMCE: fix adding of too many undo levels for wpviews. The HTML changes several times when a wpview is added. We only want one undo level. Also fixes cases when the cursor is next to an embeddable URL in the Text tab and the user switches to the Visual tab.

See #45307.

Location:
trunk/src/js/_enqueues
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/vendor/tinymce/plugins/wpview/plugin.js

    r44718 r45631  
    2626                        }
    2727
    28                         if ( ! content ) {
     28                        if ( ! content || content.indexOf( ' data-wpview-' ) === -1 ) {
    2929                                return content;
    3030                        }
    … …  
    112112                } );
    113113
    114                 // Replace views with their text inside undo levels.
    115                 // This also prevents that new levels are added when there are changes inside the views.
     114                // Prevent adding of undo levels when replacing wpview markers
     115                // or when there are changes only in the (non-editable) previews.
    116116                editor.on( 'beforeaddundo', function( event ) {
    117                         event.level.content = resetViews( event.level.content );
     117                        var lastContent;
     118                        var newContent = event.level.content || ( event.level.fragments && event.level.fragments.join( '' ) );
     119
     120                        if ( ! event.lastLevel ) {
     121                                lastContent = editor.startContent;
     122                        } else {
     123                                lastContent = event.lastLevel.content || ( event.lastLevel.fragments && event.lastLevel.fragments.join( '' ) );
     124                        }
     125
     126                        if (
     127                                ! newContent ||
     128                                ! lastContent ||
     129                                newContent.indexOf( ' data-wpview-' ) === -1 ||
     130                                lastContent.indexOf( ' data-wpview-' ) === -1
     131                        ) {
     132                                return;
     133                        }
     134
     135                        if ( resetViews( lastContent ) === resetViews( newContent ) ) {
     136                                event.preventDefault();
     137                        }
    118138                } );
    119139
  • trunk/src/js/_enqueues/wp/mce-view.js

    r43347 r45631  
    445445                                );
    446446
    447                                 editor.$( node ).replaceWith( $viewNode );
     447                                editor.undoManager.ignore( function() {
     448                                        editor.$( node ).replaceWith( $viewNode );
     449                                } );
    448450
    449451                                if ( selected ) {
    450452                                        setTimeout( function() {
    451                                                 editor.selection.select( $viewNode[0] );
    452                                                 editor.selection.collapse();
     453                                                editor.undoManager.ignore( function() {
     454                                                        editor.selection.select( $viewNode[0] );
     455                                                        editor.selection.collapse();
     456                                                } );
    453457                                        } );
    454458                                }
    … …  
    962966        views.register( 'embedURL', _.extend( {}, embed, {
    963967                match: function( content ) {
    964                         var re = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,
    965                                 match = re.exec( content );
     968                        // There may be a "bookmark" node next to the URL...
     969                        var re = /(^|<p>(?:<span data-mce-type="bookmark"[^>]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:<span data-mce-type="bookmark"[^>]+>\s*<\/span>)?<\/p>\s*|$)/gi;
     970                        var match = re.exec( content );
    966971
    967972                        if ( match ) {
Note: See TracChangeset for help on using the changeset viewer.