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

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


git-svn-id: https://develop.svn.wordpress.org/trunk@42012 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-10-24 23:26:38 +00:00
parent 3e9a42ed27
commit 2d249b2535
1 changed files with 9 additions and 1 deletions

View File

@ -247,7 +247,8 @@ $availableStructureTags.on( 'click', function() {
selectionStart = $permalinkStructure[ 0 ].selectionStart,
selectionEnd = $permalinkStructure[ 0 ].selectionEnd,
textToAppend = $( this ).text().trim(),
textToAnnounce = $( this ).attr( 'data-added' );
textToAnnounce = $( this ).attr( 'data-added' ),
newSelectionStart;
// Remove structure tag if already part of the structure.
if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) {
@ -288,6 +289,13 @@ $availableStructureTags.on( 'click', function() {
// Disable button.
changeStructureTagButtonState( $( this ) );
// If input had focus give it back with cursor right after appended text.
if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) {
newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length;
$permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart );
$permalinkStructure.focus();
}
} );
$document.ready( function() {