Editor: fix jumpiness on pressing backspace and delete in the Text editor.

Merge of [38426] to the 4.6 branch.

Props azaozz.
Fixes #37690.

Built from https://develop.svn.wordpress.org/branches/4.6@38487


git-svn-id: http://core.svn.wordpress.org/branches/4.6@38428 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2016-08-31 23:13:30 +00:00
parent b6151949af
commit 0c064f4ed8
4 changed files with 44 additions and 40 deletions

View File

@ -53,6 +53,47 @@
sideSortablesHeight: 0
};
var shrinkTextarea = window._.throttle( function() {
var x = window.scrollX || document.documentElement.scrollLeft;
var y = window.scrollY || document.documentElement.scrollTop;
var height = parseInt( textEditor.style.height, 10 );
textEditor.style.height = autoresizeMinHeight + 'px';
if ( textEditor.scrollHeight > autoresizeMinHeight ) {
textEditor.style.height = textEditor.scrollHeight + 'px';
}
if ( typeof x !== 'undefined' ) {
window.scrollTo( x, y );
}
if ( textEditor.scrollHeight < height ) {
adjust();
}
}, 300 );
function textEditorResize() {
var length = textEditor.value.length;
if ( mceEditor && ! mceEditor.isHidden() ) {
return;
}
if ( ! mceEditor && initialMode === 'tinymce' ) {
return;
}
if ( length < oldTextLength ) {
shrinkTextarea();
} else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px';
adjust();
}
oldTextLength = length;
}
function getHeights() {
var windowWidth = $window.width();
@ -75,43 +116,6 @@
}
}
function textEditorResize() {
if ( mceEditor && ! mceEditor.isHidden() ) {
return;
}
if ( ! mceEditor && initialMode === 'tinymce' ) {
return;
}
var length = textEditor.value.length;
var height = parseInt( textEditor.style.height, 10 );
var top = window.scrollTop;
if ( length < oldTextLength ) {
// textEditor.scrollHeight is not adjusted until the next line.
textEditor.style.height = 'auto';
if ( textEditor.scrollHeight > autoresizeMinHeight ) {
textEditor.style.height = textEditor.scrollHeight + 'px';
} else {
textEditor.style.height = autoresizeMinHeight + 'px';
}
// Prevent scroll-jumping in Firefox and IE.
window.scrollTop = top;
if ( textEditor.scrollHeight < height ) {
adjust();
}
} else if ( height < textEditor.scrollHeight ) {
textEditor.style.height = textEditor.scrollHeight + 'px';
adjust();
}
oldTextLength = length;
}
// We need to wait for TinyMCE to initialize.
$document.on( 'tinymce-editor-init.editor-expand', function( event, editor ) {
var VK = window.tinymce.util.VK,

File diff suppressed because one or more lines are too long

View File

@ -563,7 +563,7 @@ function wp_default_scripts( &$scripts ) {
'suggestedImgAlt' => __( 'Suggested image #%d' ),
) );
$scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery' ), false, 1 );
$scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );
$scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6.1-alpha-38485';
$wp_version = '4.6.1-alpha-38487';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.