Make WordPress Core

Ticket #45947: 45947.diff

File 45947.diff, 1.3 KB (added by iCaleb, 5 years ago)

First pass at 45947. Update regex to also match HTML comments to allow the cursor to always be moved outside of them when switching views.

  • src/js/_enqueues/wp/editor/base.js

    diff --git a/src/js/_enqueues/wp/editor/base.js b/src/js/_enqueues/wp/editor/base.js
    index c3ef2238af..0620b312de 100644
    a b window.wp = window.wp || {}; 
    188188                }
    189189
    190190                /**
    191                  * Checks if a cursor is inside an HTML tag.
     191                 * Checks if a cursor is inside an HTML tag or comment.
    192192                 *
    193193                 * In order to prevent breaking HTML tags when selecting text, the cursor
    194194                 * must be moved to either the start or end of the tag.
    window.wp = window.wp || {}; 
    211211                        if ( lastLtPos > lastGtPos || content.substr( cursorPosition, 1 ) === '>' ) {
    212212                                // find what the tag is
    213213                                var tagContent = content.substr( lastLtPos ),
    214                                         tagMatch = tagContent.match( /<\s*(\/)?(\w+)/ );
     214                                        tagMatch = tagContent.match( /<\s*(\/)?(\w+|\!-{2}.*-{2})/ );
    215215
    216216                                if ( ! tagMatch ) {
    217217                                        return null;
    window.wp = window.wp || {}; 
    382382                }
    383383
    384384                /**
    385                  * Gets adjusted selection cursor positions according to HTML tags/shortcodes
     385                 * Gets adjusted selection cursor positions according to HTML tags, comments, and shortcodes.
    386386                 *
    387387                 * Shortcodes and HTML codes are a bit of a special case when selecting, since they may render
    388388                 * content in Visual mode. If we insert selection markers somewhere inside them, it's really possible