diff --git a/src/wp-admin/js/editor-expand.js b/src/wp-admin/js/editor-expand.js index 260ee25513..35f5ea5ac9 100644 --- a/src/wp-admin/js/editor-expand.js +++ b/src/wp-admin/js/editor-expand.js @@ -31,6 +31,8 @@ jQuery( document ).ready( function($) { fixedSideBottom = false, scrollTimer, lastScrollPosition = 0, + visualEditorScrollPosition = 0, + textEditorScrollPosition = 0, pageYOffsetAtTop = 130, pinnedToolsTop = 56, sidebarBottom = 20, @@ -224,20 +226,35 @@ jQuery( document ).ready( function($) { // Adjust when switching editor modes. function mceShow() { + textEditorScrollPosition = window.pageYOffset; + setTimeout( function() { + var top = $contentWrap.offset().top; + + if ( window.pageYOffset > top || visualEditorScrollPosition ) { + window.scrollTo( window.pageXOffset, visualEditorScrollPosition ? visualEditorScrollPosition : top - heights.adminBarHeight ); + } + editor.execCommand( 'wpAutoResize' ); adjust(); }, 300 ); + + adjust(); } function mceHide() { - var wrapHeight = $( '#wpwrap' ).height(); + visualEditorScrollPosition = window.pageYOffset; - textEditorResize(); + setTimeout( function() { + var top = $contentWrap.offset().top; - if ( wrapHeight && $window.scrollTop() > wrapHeight ) { - window.scrollTo( window.pageXOffset, wrapHeight - 1 ); - } + if ( window.pageYOffset > top || textEditorScrollPosition ) { + window.scrollTo( window.pageXOffset, textEditorScrollPosition ? textEditorScrollPosition : top - heights.adminBarHeight ); + } + + textEditorResize(); + adjust(); + }, 100 ); adjust(); }