Make WordPress Core

Changeset 38426


Ignore:
Timestamp:
08/28/2016 06:40:00 PM (10 years ago)
Author:
azaozz
Message:

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

Fixes #37690 for trunk.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/editor-expand.js

    r37684 r38426  
    5454                        };
    5555
     56                var shrinkTextarea = window._.throttle( function() {
     57                        var x = window.scrollX || document.documentElement.scrollLeft;
     58                        var y = window.scrollY || document.documentElement.scrollTop;
     59                        var height = parseInt( textEditor.style.height, 10 );
     60
     61                        textEditor.style.height = autoresizeMinHeight + 'px';
     62
     63                        if ( textEditor.scrollHeight > autoresizeMinHeight ) {
     64                                textEditor.style.height = textEditor.scrollHeight + 'px';
     65                        }
     66
     67                        if ( typeof x !== 'undefined' ) {
     68                                window.scrollTo( x, y );
     69                        }
     70
     71                        if ( textEditor.scrollHeight < height ) {
     72                                adjust();
     73                        }
     74                }, 300 );
     75
     76                function textEditorResize() {
     77                        var length = textEditor.value.length;
     78
     79                        if ( mceEditor && ! mceEditor.isHidden() ) {
     80                                return;
     81                        }
     82
     83                        if ( ! mceEditor && initialMode === 'tinymce' ) {
     84                                return;
     85                        }
     86
     87                        if ( length < oldTextLength ) {
     88                                shrinkTextarea();
     89                        } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
     90                                textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px';
     91                                adjust();
     92                        }
     93
     94                        oldTextLength = length;
     95                }
     96
    5697                function getHeights() {
    5798                        var windowWidth = $window.width();
     
    74115                                heights.menuBarHeight = 0;
    75116                        }
    76                 }
    77 
    78                 function textEditorResize() {
    79                         if ( mceEditor && ! mceEditor.isHidden() ) {
    80                                 return;
    81                         }
    82 
    83                         if ( ! mceEditor && initialMode === 'tinymce' ) {
    84                                 return;
    85                         }
    86 
    87                         var length = textEditor.value.length;
    88                         var height = parseInt( textEditor.style.height, 10 );
    89                         var top = window.scrollTop;
    90 
    91                         if ( length < oldTextLength ) {
    92                                 // textEditor.scrollHeight is not adjusted until the next line.
    93                                 textEditor.style.height = 'auto';
    94 
    95                                 if ( textEditor.scrollHeight > autoresizeMinHeight ) {
    96                                         textEditor.style.height = textEditor.scrollHeight + 'px';
    97                                 } else {
    98                                         textEditor.style.height = autoresizeMinHeight + 'px';
    99                                 }
    100 
    101                                 // Prevent scroll-jumping in Firefox and IE.
    102                                 window.scrollTop = top;
    103 
    104                                 if ( textEditor.scrollHeight < height ) {
    105                                         adjust();
    106                                 }
    107                         } else if ( height < textEditor.scrollHeight ) {
    108                                 textEditor.style.height = textEditor.scrollHeight + 'px';
    109                                 adjust();
    110                         }
    111 
    112                         oldTextLength = length;
    113117                }
    114118
  • trunk/src/wp-includes/script-loader.php

    r38411 r38426  
    555555                ) );
    556556
    557                 $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery' ), false, 1 );
     557                $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );
    558558
    559559                $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.