} );
$textarea.on( 'keydown', function onKeydown( event ) {
- var selectionStart, selectionEnd, value, scroll, tabKeyCode = 9, escKeyCode = 27;
+ var selectionStart, selectionEnd, value, tabKeyCode = 9, escKeyCode = 27;
if ( escKeyCode === event.keyCode ) {
if ( ! $textarea.data( 'next-tab-blurs' ) ) {
value = textarea.value;
if ( selectionStart >= 0 ) {
- scroll = $textarea.scrollTop;
textarea.value = value.substring( 0, selectionStart ).concat( '\t', value.substring( selectionEnd ) );
$textarea.selectionStart = textarea.selectionEnd = selectionStart + 1;
- textarea.scrollTop = scroll;
}
event.stopPropagation();
// Focus on the control that is associated with the given setting.
api.previewer.bind( 'focus-control-for-setting', function( settingId ) {
- var matchedControl;
+ var matchedControls = [];
api.control.each( function( control ) {
var settingIds = _.pluck( control.settings, 'id' );
if ( -1 !== _.indexOf( settingIds, settingId ) ) {
- matchedControl = control;
+ matchedControls.push( control );
}
} );
- if ( matchedControl ) {
- matchedControl.focus();
+ // Focus on the matched control with the lowest priority (appearing higher).
+ if ( matchedControls.length ) {
+ matchedControls.sort( function( a, b ) {
+ return a.priority() - b.priority();
+ } );
+ matchedControls[0].focus();
}
} );