WordPress.org

Make WordPress Core

Changeset 42012


Ignore:
Timestamp:
10/24/2017 11:26:38 PM (2 years ago)
Author:
westonruter
Message:

Permalinks: Fix placement of structure tags based on last cursor position.

Props felipeelia, afercia.
See #29872.
Fixes #42042.

File:
1 edited

Legend:

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

    r41598 r42012  
    248248        selectionEnd            = $permalinkStructure[ 0 ].selectionEnd,
    249249        textToAppend            = $( this ).text().trim(),
    250         textToAnnounce          = $( this ).attr( 'data-added' );
     250        textToAnnounce          = $( this ).attr( 'data-added' ),
     251        newSelectionStart;
    251252
    252253    // Remove structure tag if already part of the structure.
     
    289290    // Disable button.
    290291    changeStructureTagButtonState( $( this ) );
     292
     293    // If input had focus give it back with cursor right after appended text.
     294    if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) {
     295        newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length;
     296        $permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart );
     297        $permalinkStructure.focus();
     298    }
    291299} );
    292300
Note: See TracChangeset for help on using the changeset viewer.