Media: Add Ctrl/Command + Enter shortcut to insert selected Media Library items.
Adds a Ctrl/Command + Enter keyboard shortcut to insert the currently selected single media or multiple media items when selecting in the Media Library modal. Props poena, hirschferkel, antpb, joedolson, skobe, rcreators, plaidharper. Fixes #60369. Built from https://develop.svn.wordpress.org/trunk@59035 git-svn-id: http://core.svn.wordpress.org/trunk@58431 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1da67e31b5
commit
2bc0e28dfe
|
@ -3072,6 +3072,11 @@ Attachment = View.extend(/** @lends wp.media.view.Attachment.prototype */{
|
|||
method = 'toggle';
|
||||
}
|
||||
|
||||
// Avoid toggles when the command or control key is pressed with the enter key to prevent deselecting the last selected attachment.
|
||||
if ( ( event.metaKey || event.ctrlKey ) && ( 13 === event.keyCode || 10 === event.keyCode ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.toggleSelection({
|
||||
method: method
|
||||
});
|
||||
|
@ -8428,6 +8433,29 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{
|
|||
this.escape();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the selection of attachments when the command or control key is pressed with the enter key.
|
||||
*
|
||||
* @since 6.7
|
||||
*
|
||||
* @param {Object} event The keydown event object.
|
||||
*/
|
||||
selectHandler: function( event ) {
|
||||
var selection = this.controller.state().get( 'selection' );
|
||||
|
||||
if ( ! selection.length > 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'insert' === this.controller.options.state ) {
|
||||
this.controller.trigger( 'insert', selection );
|
||||
} else {
|
||||
this.controller.trigger( 'select', selection );
|
||||
event.preventDefault();
|
||||
this.escape();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array|Object} content Views to register to '.media-modal-content'
|
||||
* @return {wp.media.view.Modal} Returns itself to allow chaining.
|
||||
|
@ -8462,6 +8490,13 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{
|
|||
this.escape();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
// Select the attachment when command or control and enter are pressed.
|
||||
if ( ( 13 === event.which || 10 === event.which ) && ( event.metaKey || event.ctrlKey ) ) {
|
||||
this.selectHandler( event );
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.7-alpha-59034';
|
||||
$wp_version = '6.7-alpha-59035';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue