Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onCopy = ( event ) => {
const selectedBlockClientIds = getSelectedBlockClientIds();
if ( selectedBlockClientIds.length === 0 ) {
clearCopiedMarkup();
return;
}
// Let native copy behaviour take over in input fields.
if ( ! hasMultiSelection() && documentHasSelection() ) {
clearCopiedMarkup();
return;
}
// Don't allow story blocks to be copyied.
for ( const selectedBlockClientId of selectedBlockClientIds ) {
if ( isPageBlock( selectedBlockClientId ) ) {
clearCopiedMarkup();
return;
}
}
const copyBlocks = getBlocksByClientId( selectedBlockClientIds );
const serialized = serialize( copyBlocks );
// Workout what type of event, from event object passed to this function.
const isCut = ( event.type === 'cut' );
const onCopy = ( event ) => {
const selectedBlockClientIds = getSelectedBlockClientIds();
if ( selectedBlockClientIds.length === 0 ) {
return;
}
// Let native copy behaviour take over in input fields.
if ( ! hasMultiSelection() && documentHasSelection() ) {
return;
}
const serialized = serialize( getBlocksByClientId( selectedBlockClientIds ) );
event.clipboardData.setData( 'text/plain', serialized );
event.clipboardData.setData( 'text/html', serialized );
event.preventDefault();
};