Skip to content
Prev Previous commit
Next Next commit
Don't flash content blocks when double clicking
  • Loading branch information
noisysocks committed Jun 13, 2023
commit 11fb8889c2115bb53db6544388298edf7acb2f13
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,50 @@ export function usePageContentFlash( contentRef ) {
if ( ! canvas ) {
return;
}
const flashContentBlocks = () => {
// const clientIds = __experimentalGetGlobalBlocksByName(
// PAGE_CONTENT_BLOCK_TYPES
// );
// for ( const clientId of clientIds ) {
// flashBlock( clientId );
// }
canvas
.querySelectorAll(
PAGE_CONTENT_BLOCK_TYPES.map(
( blockType ) => `[data-type="${ blockType }"]`
).join( ',' )
// '.block-editor-block-list__block:not(.is-editing-disabled)'
)
.forEach( ( block ) => {
const flash = async () => {
block.classList.add( 'is-highlighted' );
await new Promise( ( resolve ) =>
setTimeout( resolve, 150 )
);
block.classList.remove( 'is-highlighted' );
};
flash();
} );
};
let timeout;
const handleClick = ( event ) => {
if (
event.target.classList.contains( 'is-root-container' ) &&
event.detail === 1
) {
timeout = setTimeout( flashContentBlocks, 300 );
}
};
const handleDblClick = ( event ) => {
if ( event.target.classList.contains( 'is-root-container' ) ) {
// const clientIds = __experimentalGetGlobalBlocksByName(
// PAGE_CONTENT_BLOCK_TYPES
// );
// for ( const clientId of clientIds ) {
// flashBlock( clientId );
// }
canvas
.querySelectorAll(
PAGE_CONTENT_BLOCK_TYPES.map(
( blockType ) => `[data-type="${ blockType }"]`
).join( ',' )
// '.block-editor-block-list__block:not(.is-editing-disabled)'
)
.forEach( ( block ) => {
const flash = async () => {
block.classList.add( 'is-highlighted' );
await new Promise( ( resolve ) =>
setTimeout( resolve, 150 )
);
block.classList.remove( 'is-highlighted' );
};
flash();
} );
clearTimeout( timeout );
}
};
canvas.addEventListener( 'click', handleClick );
return () => canvas.removeEventListener( 'click', handleClick );
canvas.addEventListener( 'dblclick', handleDblClick );
return () => {
canvas.removeEventListener( 'click', handleClick );
canvas.removeEventListener( 'dblclick', handleDblClick );
};
}, [ contentRef.current ] );
}