WordPress.org

Make WordPress Core

Changeset 42175


Ignore:
Timestamp:
11/14/2017 05:18:10 AM (4 years ago)
Author:
pento
Message:

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.

Fixes #42530.

File:
1 edited

Legend:

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

    r41785 r42175  
    635635                selectionPosition = TinyMCEContentAreaTop + elementTop,
    636636                visibleAreaHeight = windowHeight - ( edToolsHeight + toolbarHeight );
     637
     638            // There's no need to scroll if the selection is inside the visible area.
     639            if ( selectionPosition < visibleAreaHeight ) {
     640                return;
     641            }
    637642
    638643            /**
     
    853858
    854859            if ( textArea.focus ) {
    855                 // focus and scroll to the position
     860                // Wait for the Visual editor to be hidden, then focus and scroll to the position
    856861                setTimeout( function() {
     862                    textArea.setSelectionRange( start, end );
    857863                    if ( textArea.blur ) {
    858864                        // defocus before focusing
     
    861867                    textArea.focus();
    862868                }, 100 );
    863 
    864                 textArea.focus();
    865             }
    866 
    867             textArea.setSelectionRange( start, end );
     869            }
    868870        }
    869871
Note: See TracChangeset for help on using the changeset viewer.