From c9b825d5f53c1acb36c27649dcc0695e7b68207f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 15 Nov 2017 00:20:21 +0000 Subject: [PATCH] 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 trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@42183 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/editor.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/js/editor.js b/src/wp-admin/js/editor.js index a5ab98dff3..d52e6ba63b 100644 --- a/src/wp-admin/js/editor.js +++ b/src/wp-admin/js/editor.js @@ -270,7 +270,7 @@ window.wp = window.wp || {}; if ( shortcodes ) { for ( var i = 0; i < shortcodes.length; i++ ) { var shortcode = shortcodes[ i ].replace( /^\[+/g, '' ); - + if ( result.indexOf( shortcode ) === -1 ) { result.push( shortcode ); } @@ -581,6 +581,8 @@ window.wp = window.wp || {}; removeSelectionMarker( startNode ); removeSelectionMarker( endNode ); + + editor.save(); } /** @@ -623,7 +625,9 @@ window.wp = window.wp || {}; edTools = $( '#wp-content-editor-tools' ), edToolsHeight = 0, - edToolsOffsetTop = 0; + edToolsOffsetTop = 0, + + $scrollArea; if ( edTools.length ) { 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 * 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 ) }, 100 ); }