Editor: Improve scrolling behavior and prevent autosave logic from causing dirty state when just switching between Visual and Text tabs.

Props pento.
See #41962, #42029.
Fixes #42530 for 4.9.

Built from https://develop.svn.wordpress.org/branches/4.9@42184


git-svn-id: http://core.svn.wordpress.org/branches/4.9@42014 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-11-15 00:22:42 +00:00
parent 36282a2a9c
commit ecf8680978
3 changed files with 17 additions and 6 deletions

View File

@ -270,7 +270,7 @@ window.wp = window.wp || {};
if ( shortcodes ) { if ( shortcodes ) {
for ( var i = 0; i < shortcodes.length; i++ ) { for ( var i = 0; i < shortcodes.length; i++ ) {
var shortcode = shortcodes[ i ].replace( /^\[+/g, '' ); var shortcode = shortcodes[ i ].replace( /^\[+/g, '' );
if ( result.indexOf( shortcode ) === -1 ) { if ( result.indexOf( shortcode ) === -1 ) {
result.push( shortcode ); result.push( shortcode );
} }
@ -581,6 +581,8 @@ window.wp = window.wp || {};
removeSelectionMarker( startNode ); removeSelectionMarker( startNode );
removeSelectionMarker( endNode ); removeSelectionMarker( endNode );
editor.save();
} }
/** /**
@ -623,7 +625,9 @@ window.wp = window.wp || {};
edTools = $( '#wp-content-editor-tools' ), edTools = $( '#wp-content-editor-tools' ),
edToolsHeight = 0, edToolsHeight = 0,
edToolsOffsetTop = 0; edToolsOffsetTop = 0,
$scrollArea;
if ( edTools.length ) { if ( edTools.length ) {
edToolsHeight = edTools.height(); edToolsHeight = edTools.height();
@ -648,9 +652,16 @@ window.wp = window.wp || {};
* subtracting the height. This gives the scroll position where the top of the editor tools aligns with * subtracting the height. This gives the scroll position where the top of the editor tools aligns with
* the top of the viewport (under the Master Bar) * the top of the viewport (under the Master Bar)
*/ */
var adjustedScroll = Math.max( selectionPosition - visibleAreaHeight / 2, edToolsOffsetTop - edToolsHeight ); var adjustedScroll;
if ( editor.settings.wp_autoresize_on ) {
$scrollArea = $( 'html,body' );
adjustedScroll = Math.max( selectionPosition - visibleAreaHeight / 2, edToolsOffsetTop - edToolsHeight );
} else {
$scrollArea = $( editor.contentDocument ).find( 'html,body' );
adjustedScroll = elementTop;
}
$( 'html,body' ).animate( { $scrollArea.animate( {
scrollTop: parseInt( adjustedScroll, 10 ) scrollTop: parseInt( adjustedScroll, 10 )
}, 100 ); }, 100 );
} }

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-RC3-42182'; $wp_version = '4.9-RC3-42184';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.