Editor: When switching Editor tabs, don't scroll unnecessarily.

- When switching to the Text view, wait until after the Visual editor element has been hidden, before focussing the `<textarea>`.
- When switching to the Visual view, only scroll if the cursor is not visible on the current screen.

Merge of 52175 to the 4.9 branch.

Fixes #42530.


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


git-svn-id: http://core.svn.wordpress.org/branches/4.9@42006 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2017-11-14 05:21:39 +00:00
parent eb18399c10
commit 5e736b62e0
3 changed files with 9 additions and 7 deletions

View File

@ -635,6 +635,11 @@ window.wp = window.wp || {};
selectionPosition = TinyMCEContentAreaTop + elementTop,
visibleAreaHeight = windowHeight - ( edToolsHeight + toolbarHeight );
// There's no need to scroll if the selection is inside the visible area.
if ( selectionPosition < visibleAreaHeight ) {
return;
}
/**
* The minimum scroll height should be to the top of the editor, to offer a consistent
* experience.
@ -852,19 +857,16 @@ window.wp = window.wp || {};
end = selection.end || selection.start;
if ( textArea.focus ) {
// focus and scroll to the position
// Wait for the Visual editor to be hidden, then focus and scroll to the position
setTimeout( function() {
textArea.setSelectionRange( start, end );
if ( textArea.blur ) {
// defocus before focusing
textArea.blur();
}
textArea.focus();
}, 100 );
textArea.focus();
}
textArea.setSelectionRange( start, end );
}
// Restore the selection when the editor is initialized. Needed when the Text editor is the default.

File diff suppressed because one or more lines are too long

View File

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