Make WordPress Core

Changeset 42575


Ignore:
Timestamp:
01/23/2018 05:47:52 PM (9 years ago)
Author:
azaozz
Message:

Merged revision 42574 from trunk:

Editor: when keeping the scroll position treat all shortcodes as preview-able. Otherwise in some cases the marker span can get stuck inside the shortcode and break the markup.

Props azaozz, lizkarkoski and othellobloke for testing.
Fixes #42908 for 4.9.3.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/js/editor.js

    r42442 r42575  
    282282
    283283                /**
    284                  * @summary Check if a shortcode has Live Preview enabled for it.
    285                  *
    286                  * Previewable shortcodes here refers to shortcodes that have Live Preview enabled.
    287                  *
    288                  * These shortcodes get rewritten when the editor is in Visual mode, which means that
    289                  * we don't want to change anything inside them, i.e. inserting a selection marker
    290                  * inside the shortcode will break it :(
    291                  *
    292                  * @link wp-includes/js/mce-view.js
    293                  *
    294                  * @param {string} shortcode The shortcode to check.
    295                  * @return {boolean} If a shortcode has Live Preview or not
    296                  */
    297                 function isShortcodePreviewable( shortcode ) {
    298                         var defaultPreviewableShortcodes = [ 'caption' ];
    299 
    300                         return (
    301                                 defaultPreviewableShortcodes.indexOf( shortcode ) !== -1 ||
    302                                 wp.mce.views.get( shortcode ) !== undefined
    303                         );
    304 
    305                 }
    306 
    307                 /**
    308284                 * @summary Get all shortcodes and their positions in the content
    309285                 *
    … …  
    341317                                var showAsPlainText = shortcodeMatch[1] === '[';
    342318
    343                                 /**
    344                                  * For more context check the docs for:
    345                                  *
    346                                  * @link isShortcodePreviewable
    347                                  *
    348                                  * In addition, if the shortcode will get rendered as plain text ( see above ),
    349                                  * we can treat it as text and use the selection markers in it.
    350                                  */
    351                                 var isPreviewable = ! showAsPlainText && isShortcodePreviewable( shortcodeMatch[2] );
    352 
    353319                                shortcodeInfo = {
    354320                                        shortcodeName: shortcodeMatch[2],
    … …  
    356322                                        startIndex: shortcodeMatch.index,
    357323                                        endIndex: shortcodeMatch.index + shortcodeMatch[0].length,
    358                                         length: shortcodeMatch[0].length,
    359                                         isPreviewable: isPreviewable
     324                                        length: shortcodeMatch[0].length
    360325                                };
    361326
    … …  
    383348                                        endIndex: shortcodeMatch.index + shortcodeMatch[ 0 ].length,
    384349                                        length: shortcodeMatch[ 0 ].length,
    385                                         isPreviewable: true,
    386350                                        urlAtStartOfContent: shortcodeMatch[ 1 ] === '',
    387351                                        urlAtEndOfContent: shortcodeMatch[ 3 ] === ''
    … …  
    466430
    467431                        var isCursorStartInShortcode = getShortcodeWrapperInfo( content, cursorStart );
    468                         if ( isCursorStartInShortcode && isCursorStartInShortcode.isPreviewable ) {
     432                        if ( isCursorStartInShortcode && ! isCursorStartInShortcode.showAsPlainText ) {
    469433                                /**
    470434                                 * If a URL is at the start or the end of the content,
    … …  
    483447
    484448                        var isCursorEndInShortcode = getShortcodeWrapperInfo( content, cursorEnd );
    485                         if ( isCursorEndInShortcode && isCursorEndInShortcode.isPreviewable ) {
     449                        if ( isCursorEndInShortcode && ! isCursorEndInShortcode.showAsPlainText ) {
    486450                                if ( isCursorEndInShortcode.urlAtEndOfContent ) {
    487451                                        cursorEnd = isCursorEndInShortcode.startIndex;
Note: See TracChangeset for help on using the changeset viewer.