Make WordPress Core

Ticket #42531: 42531.diff

File 42531.diff, 9.4 KB (added by adamsilverstein, 7 years ago)
  • src/wp-admin/edit-form-advanced.php

    diff --git src/wp-admin/edit-form-advanced.php src/wp-admin/edit-form-advanced.php
    index 07c2dfe129..cddab85c1a 100644
    if ( post_type_supports($post_type, 'editor') ) { 
    639639                'resize' => false,
    640640                'wp_autoresize_on' => $_wp_editor_expand,
    641641                'add_unload_trigger' => false,
    642                 'wp_keep_scroll_position' => true,
    643642        ),
    644643) ); ?>
    645644<table id="post-status-info"><tbody><tr>
  • src/wp-admin/js/editor.js

    diff --git src/wp-admin/js/editor.js src/wp-admin/js/editor.js
    index ed77d3c755..ea4becc7dc 100644
    window.wp = window.wp || {}; 
    9999
    100100                                editorHeight = parseInt( textarea.style.height, 10 ) || 0;
    101101
    102                                 var keepSelection = false;
    103                                 if ( editor ) {
    104                                         keepSelection = editor.getParam( 'wp_keep_scroll_position' );
    105                                 } else {
    106                                         keepSelection = window.tinyMCEPreInit.mceInit[ id ] &&
    107                                                                         window.tinyMCEPreInit.mceInit[ id ].wp_keep_scroll_position;
    108                                 }
    109 
    110                                 if ( keepSelection ) {
    111102                                        // Save the selection
    112                                         addHTMLBookmarkInTextAreaContent( $textarea );
    113                                 }
     103                                addHTMLBookmarkInTextAreaContent( $textarea, $ );
    114104
    115105                                if ( editor ) {
    116106                                        editor.show();
    window.wp = window.wp || {}; 
    126116                                                }
    127117                                        }
    128118
    129                                         if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
    130119                                                // Restore the selection
    131120                                                focusHTMLBookmarkInVisualEditor( editor );
    132                                         }
    133121                                } else {
    134122                                        tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
    135123                                }
    window.wp = window.wp || {}; 
    144132                                        return false;
    145133                                }
    146134
     135                                var selectionRange = null;
    147136                                if ( editor ) {
    148137                                        // Don't resize the textarea in iOS. The iframe is forced to 100% height there, we shouldn't match it.
    149138                                        if ( ! tinymce.Env.iOS ) {
    window.wp = window.wp || {}; 
    161150                                                }
    162151                                        }
    163152
    164                                         var selectionRange = null;
    165 
    166                                         if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
    167153                                                selectionRange = findBookmarkedPosition( editor );
    168                                         }
    169154
    170155                                        editor.hide();
    171156
    window.wp = window.wp || {}; 
    249234                function getShortcodeWrapperInfo( content, cursorPosition ) {
    250235                        var contentShortcodes = getShortCodePositionsInText( content );
    251236
    252                         for ( var i = 0; i < contentShortcodes.length; i++ ) {
    253                                 var element = contentShortcodes[ i ];
    254 
    255                                 if ( cursorPosition >= element.startIndex && cursorPosition <= element.endIndex ) {
    256                                         return element;
    257                                 }
    258                         }
     237                        return _.find( contentShortcodes, function( element ) {
     238                                return cursorPosition >= element.startIndex && cursorPosition <= element.endIndex;
     239                        } );
    259240                }
    260241
    261242                /**
    window.wp = window.wp || {}; 
    264245                 * @param {string} content The content we want to scan for shortcodes.
    265246                 */
    266247                function getShortcodesInText( content ) {
    267                         var shortcodes = content.match( /\[+([\w_-])+/g ),
    268                                 result = [];
    269 
    270                         if ( shortcodes ) {
    271                                 for ( var i = 0; i < shortcodes.length; i++ ) {
    272                                         var shortcode = shortcodes[ i ].replace( /^\[+/g, '' );
    273        
    274                                         if ( result.indexOf( shortcode ) === -1 ) {
    275                                                 result.push( shortcode );
    276                                         }
    277                                 }
    278                         }
     248                        var shortcodes = content.match( /\[+([\w_-])+/g );
     249                        return _.uniq(
    279250
    280                         return result;
     251                                _.map( shortcodes, function( element ) {
     252                                        return element.replace( /^\[+/g, '' );
     253                                } )
     254                        );
    281255                }
    282256
    283257                /**
    window.wp = window.wp || {}; 
    362336                                shortcodesDetails.push( shortcodeInfo );
    363337                        }
    364338
    365                         /**
    366                          * Get all URL matches, and treat them as embeds.
    367                          *
    368                          * Since there isn't a good way to detect if a URL by itself on a line is a previewable
    369                          * object, it's best to treat all of them as such.
    370                          *
    371                          * This means that the selection will capture the whole URL, in a similar way shrotcodes
    372                          * are treated.
    373                          */
    374                         var urlRegexp = new RegExp(
    375                                 '(^|[\\n\\r][\\n\\r]|<p>)(https?:\\/\\/[^\s"]+?)(<\\/p>\s*|[\\n\\r][\\n\\r]|$)', 'gi'
    376                         );
    377 
    378                         while ( shortcodeMatch = urlRegexp.exec( content ) ) {
    379                                 shortcodeInfo = {
    380                                         shortcodeName: 'url',
    381                                         showAsPlainText: false,
    382                                         startIndex: shortcodeMatch.index,
    383                                         endIndex: shortcodeMatch.index + shortcodeMatch[ 0 ].length,
    384                                         length: shortcodeMatch[ 0 ].length,
    385                                         isPreviewable: true,
    386                                         urlAtStartOfContent: shortcodeMatch[ 1 ] === '',
    387                                         urlAtEndOfContent: shortcodeMatch[ 3 ] === ''
    388                                 };
    389 
    390                                 shortcodesDetails.push( shortcodeInfo );
    391                         }
    392 
    393339                        return shortcodesDetails;
    394340                }
    395341
    window.wp = window.wp || {}; 
    454400                                 */
    455401                                if ( voidElements.indexOf( isCursorStartInTag.tagType ) !== -1 ) {
    456402                                        cursorStart = isCursorStartInTag.ltPos;
    457                                 } else {
     403                                }
     404                                else {
    458405                                        cursorStart = isCursorStartInTag.gtPos;
    459406                                }
    460407                        }
    window.wp = window.wp || {}; 
    466413
    467414                        var isCursorStartInShortcode = getShortcodeWrapperInfo( content, cursorStart );
    468415                        if ( isCursorStartInShortcode && isCursorStartInShortcode.isPreviewable ) {
    469                                 /**
    470                                  * If a URL is at the start or the end of the content,
    471                                  * the selection doesn't work, because it inserts a marker in the text,
    472                                  * which breaks the embedURL detection.
    473                                  *
    474                                  * The best way to avoid that and not modify the user content is to
    475                                  * adjust the cursor to either after or before URL.
    476                                  */
    477                                 if ( isCursorStartInShortcode.urlAtStartOfContent ) {
    478                                         cursorStart = isCursorStartInShortcode.endIndex;
    479                                 } else {
    480416                                        cursorStart = isCursorStartInShortcode.startIndex;
    481                                 }
    482417                        }
    483418
    484419                        var isCursorEndInShortcode = getShortcodeWrapperInfo( content, cursorEnd );
    485420                        if ( isCursorEndInShortcode && isCursorEndInShortcode.isPreviewable ) {
    486                                 if ( isCursorEndInShortcode.urlAtEndOfContent ) {
    487                                         cursorEnd = isCursorEndInShortcode.startIndex;
    488                                 } else {
    489421                                        cursorEnd = isCursorEndInShortcode.endIndex;
    490                                 }
    491422                        }
    492423
    493424                        return {
    window.wp = window.wp || {}; 
    525456                                mode = htmlModeCursorStartPosition !== htmlModeCursorEndPosition ? 'range' : 'single',
    526457
    527458                                selectedText = null,
    528                                 cursorMarkerSkeleton = getCursorMarkerSpan( $$, '&#65279;' ).attr( 'data-mce-type','bookmark' );
     459                                cursorMarkerSkeleton = getCursorMarkerSpan( $$, '&#65279;' );
    529460
    530461                        if ( mode === 'range' ) {
    531462                                var markedText = textArea.value.slice( htmlModeCursorStartPosition, htmlModeCursorEndPosition ),
    window.wp = window.wp || {}; 
    540471                        textArea.value = [
    541472                                textArea.value.slice( 0, htmlModeCursorStartPosition ), // text until the cursor/selection position
    542473                                cursorMarkerSkeleton.clone()                                                    // cursor/selection start marker
    543                                         .addClass( 'mce_SELRES_start' )[0].outerHTML,
     474                                        .addClass( 'mce_SELRES_start')[0].outerHTML,
    544475                                selectedText,                                                                                   // selected text with end cursor/position marker
    545476                                textArea.value.slice( htmlModeCursorEndPosition )               // text from last cursor/selection position to end
    546477                        ].join( '' );
    window.wp = window.wp || {}; 
    557488                 * @param {Object} editor TinyMCE editor instance.
    558489                 */
    559490                function focusHTMLBookmarkInVisualEditor( editor ) {
    560                         var startNode = editor.$( '.mce_SELRES_start' ).attr( 'data-mce-bogus', 1 ),
    561                                 endNode = editor.$( '.mce_SELRES_end' ).attr( 'data-mce-bogus', 1 );
     491                        var startNode = editor.$( '.mce_SELRES_start' ),
     492                                endNode = editor.$( '.mce_SELRES_end' );
    562493
    563494                        if ( startNode.length ) {
    564495                                editor.focus();
    window.wp = window.wp || {}; 
    575506                                }
    576507                        }
    577508
    578                         if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
    579509                                scrollVisualModeToStartElement( editor, startNode );
    580                         }
     510
    581511
    582512                        removeSelectionMarker( startNode );
    583513                        removeSelectionMarker( endNode );
    window.wp = window.wp || {}; 
    619549                        var elementTop = editor.$( element ).offset().top,
    620550                                TinyMCEContentAreaTop = editor.$( editor.getContentAreaContainer() ).offset().top,
    621551
    622                                 toolbarHeight = getToolbarHeight( editor ),
    623 
    624552                                edTools = $( '#wp-content-editor-tools' ),
    625                                 edToolsHeight = 0,
    626                                 edToolsOffsetTop = 0;
     553                                edToolsHeight = edTools.height(),
     554                                edToolsOffsetTop = edTools.offset().top,
    627555
    628                         if ( edTools.length ) {
    629                                 edToolsHeight = edTools.height();
    630                                 edToolsOffsetTop = edTools.offset().top;
    631                         }
     556                                toolbarHeight = getToolbarHeight( editor ),
    632557
    633                         var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
     558                                windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
    634559
    635560                                selectionPosition = TinyMCEContentAreaTop + elementTop,
    636561                                visibleAreaHeight = windowHeight - ( edToolsHeight + toolbarHeight );
    window.wp = window.wp || {}; 
    751676                                 * This way we can adjust the selection to properly select only the content, ignoring
    752677                                 * whitespace inserted around the selected object by the Editor.
    753678                                 */
    754                                 startElement.attr( 'data-mce-object-selection', 'true' );
    755                                 endElement.attr( 'data-mce-object-selection', 'true' );
     679                                startElement.attr('data-mce-object-selection', 'true');
     680                                endElement.attr('data-mce-object-selection', 'true');
    756681
    757682                                editor.$( startNode ).before( startElement[0] );
    758683                                editor.$( startNode ).after( endElement[0] );
  • src/wp-includes/class-wp-editor.php

    diff --git src/wp-includes/class-wp-editor.php src/wp-includes/class-wp-editor.php
    index 0743a840fe..954908be08 100644
    final class _WP_Editors { 
    983983                        'end_container_on_empty_block' => true,
    984984                        'wpeditimage_html5_captions' => true,
    985985                        'wp_lang_attr' => get_bloginfo( 'language' ),
    986                         'wp_keep_scroll_position' => false,
    987986                        'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
    988987                );
    989988