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

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

Built from https://develop.svn.wordpress.org/trunk@42012


git-svn-id: http://core.svn.wordpress.org/trunk@41846 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-10-24 23:27:48 +00:00
parent 2f3e91028a
commit d96b7af890
3 changed files with 11 additions and 3 deletions

View File

@ -247,7 +247,8 @@ $availableStructureTags.on( 'click', function() {
selectionStart = $permalinkStructure[ 0 ].selectionStart, selectionStart = $permalinkStructure[ 0 ].selectionStart,
selectionEnd = $permalinkStructure[ 0 ].selectionEnd, selectionEnd = $permalinkStructure[ 0 ].selectionEnd,
textToAppend = $( this ).text().trim(), textToAppend = $( this ).text().trim(),
textToAnnounce = $( this ).attr( 'data-added' ); textToAnnounce = $( this ).attr( 'data-added' ),
newSelectionStart;
// Remove structure tag if already part of the structure. // Remove structure tag if already part of the structure.
if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) { if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) {
@ -288,6 +289,13 @@ $availableStructureTags.on( 'click', function() {
// Disable button. // Disable button.
changeStructureTagButtonState( $( this ) ); 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() { $document.ready( function() {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-beta3-42011'; $wp_version = '4.9-beta3-42012';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.