<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41783] trunk/src: Editor:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41783">41783</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41783","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-10-06 17:43:11 +0000 (Fri, 06 Oct 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor:
- Fix keeping text selection and scroll position when there are embeds from URL.
- Add editor setting to disable keeping selection and scroll position.
- Remove dependency on Underscore.js.
- Fix error in the Text widget editor.

Props biskobe.
Fixes <a href="https://core.trac.wordpress.org/ticket/42059">#42059</a>, see <a href="https://core.trac.wordpress.org/ticket/40854">#40854</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmineditformadvancedphp">trunk/src/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunksrcwpadminjseditorjs">trunk/src/wp-admin/js/editor.js</a></li>
<li><a href="#trunksrcwpincludesclasswpeditorphp">trunk/src/wp-includes/class-wp-editor.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmineditformadvancedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/edit-form-advanced.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/edit-form-advanced.php 2017-10-06 17:36:12 UTC (rev 41782)
+++ trunk/src/wp-admin/edit-form-advanced.php   2017-10-06 17:43:11 UTC (rev 41783)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -628,6 +628,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'resize' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                'wp_autoresize_on' => $_wp_editor_expand,
</span><span class="cx" style="display: block; padding: 0 10px">                'add_unload_trigger' => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'wp_keep_scroll_position' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">         ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <table id="post-status-info"><tbody><tr>
</span></span></pre></div>
<a id="trunksrcwpadminjseditorjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/editor.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/editor.js   2017-10-06 17:36:12 UTC (rev 41782)
+++ trunk/src/wp-admin/js/editor.js     2017-10-06 17:43:11 UTC (rev 41783)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -99,9 +99,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                editorHeight = parseInt( textarea.style.height, 10 ) || 0;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Save the selection
-                               addHTMLBookmarkInTextAreaContent( $textarea, $ );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         var keepSelection = false;
+                               if ( editor ) {
+                                       keepSelection = editor.getParam( 'wp_keep_scroll_position' )
+                               } else {
+                                       keepSelection = window.tinyMCEPreInit.mceInit[ id ] &&
+                                                                       window.tinyMCEPreInit.mceInit[ id ]['wp_keep_scroll_position']
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( keepSelection ) {
+                                       // Save the selection
+                                       addHTMLBookmarkInTextAreaContent( $textarea );
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( editor ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        editor.show();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -116,8 +126,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // Restore the selection
-                                       focusHTMLBookmarkInVisualEditor( editor );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
+                                               // Restore the selection
+                                               focusHTMLBookmarkInVisualEditor( editor );
+                                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                                        tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -132,7 +144,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        return false;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                var selectionRange = null;
</del><span class="cx" style="display: block; padding: 0 10px">                                 if ( editor ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        // Don't resize the textarea in iOS. The iframe is forced to 100% height there, we shouldn't match it.
</span><span class="cx" style="display: block; padding: 0 10px">                                        if ( ! tinymce.Env.iOS ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -150,8 +161,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        selectionRange = findBookmarkedPosition( editor );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 var selectionRange = null;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
+                                               selectionRange = findBookmarkedPosition( editor );
+                                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                         editor.hide();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        if ( selectionRange ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,9 +249,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                function getShortcodeWrapperInfo( content, cursorPosition ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        var contentShortcodes = getShortCodePositionsInText( content );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return _.find( contentShortcodes, function( element ) {
-                               return cursorPosition >= element.startIndex && cursorPosition <= element.endIndex;
-                       } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 for ( var i = 0; i < contentShortcodes.length; i++ ) {
+                               var element = contentShortcodes[ i ];
+
+                               if ( cursorPosition >= element.startIndex && cursorPosition <= element.endIndex ) {
+                                       return element;
+                               }
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -245,13 +264,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * @param {string} content The content we want to scan for shortcodes.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                function getShortcodesInText( content ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var shortcodes = content.match( /\[+([\w_-])+/g );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var shortcodes = content.match( /\[+([\w_-])+/g ),
+                               result = [];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return _.uniq(
-                               _.map( shortcodes, function( element ) {
-                                       return element.replace( /^\[+/g, '' );
-                               } )
-                       );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( shortcodes ) {
+                               for ( var i = 0; i < shortcodes.length; i++ ) {
+                                       var shortcode = shortcodes[ i ].replace( /^\[+/g, '' );
+       
+                                       if ( result.indexOf( shortcode ) === -1 ) {
+                                               result.push( shortcode );
+                                       }
+                               }
+                       }
+
+                       return result;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -335,6 +361,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                shortcodesDetails.push( shortcodeInfo );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        /**
+                        * Get all URL matches, and treat them as embeds.
+                        *
+                        * Since there isn't a good way to detect if a URL by itself on a line is a previewable
+                        * object, it's best to treat all of them as such.
+                        *
+                        * This means that the selection will capture the whole URL, in a similar way shrotcodes
+                        * are treated.
+                        */
+                       var urlRegexp = new RegExp(
+                               '(^|[\\n\\r][\\n\\r]|<p>)(https?:\\/\\/[^\s"]+?)(<\\/p>\s*|[\\n\\r][\\n\\r]|$)', 'gi'
+                       );
+
+                       while ( shortcodeMatch = urlRegexp.exec( content ) ) {
+                               shortcodeInfo = {
+                                       shortcodeName: 'url',
+                                       showAsPlainText: false,
+                                       startIndex: shortcodeMatch.index,
+                                       endIndex: shortcodeMatch.index + shortcodeMatch[ 0 ].length,
+                                       length: shortcodeMatch[ 0 ].length,
+                                       isPreviewable: true,
+                                       urlAtStartOfContent: shortcodeMatch[ 1 ] === '',
+                                       urlAtEndOfContent: shortcodeMatch[ 3 ] === ''
+                               };
+
+                               shortcodesDetails.push( shortcodeInfo );
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         return shortcodesDetails;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -399,8 +453,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 */
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( voidElements.indexOf( isCursorStartInTag.tagType ) !== -1 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        cursorStart = isCursorStartInTag.ltPos;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                }
-                               else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         } else {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         cursorStart = isCursorStartInTag.gtPos;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -412,12 +465,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        var isCursorStartInShortcode = getShortcodeWrapperInfo( content, cursorStart );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( isCursorStartInShortcode && isCursorStartInShortcode.isPreviewable ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                cursorStart = isCursorStartInShortcode.startIndex;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         /**
+                                * If a URL is at the start or the end of the content,
+                                * the selection doesn't work, because it inserts a marker in the text,
+                                * which breaks the embedURL detection.
+                                *
+                                * The best way to avoid that and not modify the user content is to
+                                * adjust the cursor to either after or before URL.
+                                */
+                               if ( isCursorStartInShortcode.urlAtStartOfContent ) {
+                                       cursorStart = isCursorStartInShortcode.endIndex;
+                               } else {
+                                       cursorStart = isCursorStartInShortcode.startIndex;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        var isCursorEndInShortcode = getShortcodeWrapperInfo( content, cursorEnd );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( isCursorEndInShortcode && isCursorEndInShortcode.isPreviewable ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                cursorEnd = isCursorEndInShortcode.endIndex;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( isCursorEndInShortcode.urlAtEndOfContent ) {
+                                       cursorEnd = isCursorEndInShortcode.startIndex;
+                               } else {
+                                       cursorEnd = isCursorEndInShortcode.endIndex;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        return {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -455,7 +524,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                mode = htmlModeCursorStartPosition !== htmlModeCursorEndPosition ? 'range' : 'single',
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                selectedText = null,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                cursorMarkerSkeleton = getCursorMarkerSpan( $$, '&#65279;' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         cursorMarkerSkeleton = getCursorMarkerSpan( $$, '&#65279;' ).attr( 'data-mce-type','bookmark' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( mode === 'range' ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                var markedText = textArea.value.slice( htmlModeCursorStartPosition, htmlModeCursorEndPosition ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -470,7 +539,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        textArea.value = [
</span><span class="cx" style="display: block; padding: 0 10px">                                textArea.value.slice( 0, htmlModeCursorStartPosition ), // text until the cursor/selection position
</span><span class="cx" style="display: block; padding: 0 10px">                                cursorMarkerSkeleton.clone()                                                    // cursor/selection start marker
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        .addClass( 'mce_SELRES_start')[0].outerHTML,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 .addClass( 'mce_SELRES_start' )[0].outerHTML,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 selectedText,                                                                                   // selected text with end cursor/position marker
</span><span class="cx" style="display: block; padding: 0 10px">                                textArea.value.slice( htmlModeCursorEndPosition )               // text from last cursor/selection position to end
</span><span class="cx" style="display: block; padding: 0 10px">                        ].join( '' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -487,8 +556,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * @param {Object} editor TinyMCE editor instance.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                function focusHTMLBookmarkInVisualEditor( editor ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var startNode = editor.$( '.mce_SELRES_start' ),
-                               endNode = editor.$( '.mce_SELRES_end' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var startNode = editor.$( '.mce_SELRES_start' ).attr( 'data-mce-bogus', 1 ),
+                               endNode = editor.$( '.mce_SELRES_end' ).attr( 'data-mce-bogus', 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( startNode.length ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.focus();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -505,9 +574,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        scrollVisualModeToStartElement( editor, startNode );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( editor.getParam( 'wp_keep_scroll_position' ) ) {
+                               scrollVisualModeToStartElement( editor, startNode );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                         removeSelectionMarker( startNode );
</span><span class="cx" style="display: block; padding: 0 10px">                        removeSelectionMarker( endNode );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -548,13 +618,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        var elementTop = editor.$( element ).offset().top,
</span><span class="cx" style="display: block; padding: 0 10px">                                TinyMCEContentAreaTop = editor.$( editor.getContentAreaContainer() ).offset().top,
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                toolbarHeight = getToolbarHeight( editor ),
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 edTools = $( '#wp-content-editor-tools' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                edToolsHeight = edTools.height(),
-                               edToolsOffsetTop = edTools.offset().top,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         edToolsHeight = 0,
+                               edToolsOffsetTop = 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                toolbarHeight = getToolbarHeight( editor ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( edTools.length ) {
+                               edToolsHeight = edTools.height();
+                               edToolsOffsetTop = edTools.offset().top;
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                selectionPosition = TinyMCEContentAreaTop + elementTop,
</span><span class="cx" style="display: block; padding: 0 10px">                                visibleAreaHeight = windowHeight - ( edToolsHeight + toolbarHeight );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -675,8 +750,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 * This way we can adjust the selection to properly select only the content, ignoring
</span><span class="cx" style="display: block; padding: 0 10px">                                 * whitespace inserted around the selected object by the Editor.
</span><span class="cx" style="display: block; padding: 0 10px">                                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                startElement.attr('data-mce-object-selection', 'true');
-                               endElement.attr('data-mce-object-selection', 'true');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         startElement.attr( 'data-mce-object-selection', 'true' );
+                               endElement.attr( 'data-mce-object-selection', 'true' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.$( startNode ).before( startElement[0] );
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.$( startNode ).after( endElement[0] );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpeditorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-editor.php 2017-10-06 17:36:12 UTC (rev 41782)
+++ trunk/src/wp-includes/class-wp-editor.php   2017-10-06 17:43:11 UTC (rev 41783)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -981,6 +981,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'end_container_on_empty_block' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'wpeditimage_html5_captions' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'wp_lang_attr' => get_bloginfo( 'language' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'wp_keep_scroll_position' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>