How to use the @wordpress/dom.documentHasSelection function in @wordpress/dom

To help you get started, we’ve selected a few @wordpress/dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ampproject / amp-wp / assets / src / stories-editor / blocks / amp-story-page / copy-paste-handler.js View on Github external
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' );
github WordPress / gutenberg / packages / block-editor / src / components / copy-handler / index.js View on Github external
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();
		};