Make WordPress Core

Changeset 42176


Ignore:
Timestamp:
11/14/2017 05:20:24 AM (6 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.

Merge of 52175 to the 4.9 branch.

Fixes #42530.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/js/editor.js

    r41785 r42176  
    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.