From 9091dc1f4e3e0cdee8f48f0b15c3bb193fdb2268 Mon Sep 17 00:00:00 2001 From: iseulde Date: Wed, 22 Aug 2018 15:23:28 +0200 Subject: [PATCH] Allow text to be dragged out of blocks --- .../editor/src/components/block-list/block.js | 18 +++++++++++++++--- .../editor/src/components/block-list/layout.js | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/block-list/block.js b/packages/editor/src/components/block-list/block.js index 4d32a8069dc125..de1993b4748781 100644 --- a/packages/editor/src/components/block-list/block.js +++ b/packages/editor/src/components/block-list/block.js @@ -254,15 +254,27 @@ export class BlockListBlock extends Component { } /** - * Prevents default dragging behavior within a block to allow for multi- - * selection to take effect unhampered. + * Handle dragging behavior within a block to allow for multi-selection or + * dragging selected text to take effect unhampered. If dragging selected + * text, current multi-selection should revert and stop. Any other drag + * behaviour should be default prevented. * * @param {DragEvent} event Drag event. * * @return {void} */ preventDrag( event ) { - event.preventDefault(); + // If there is plain text being transferred, this means that there is a + // text selection being dragged. Images, for example, have HTML transfer + // data, but no plain text. + if ( event.dataTransfer.getData( 'text/plain' ) ) { + // Cancel multi-selection. + this.props.onSelectionEnd(); + // Revert to selecting the block if there is multi-selection. + this.props.onSelect(); + } else { + event.preventDefault(); + } } /** diff --git a/packages/editor/src/components/block-list/layout.js b/packages/editor/src/components/block-list/layout.js index 59a9d8377875ac..6fb92b69ec6c50 100644 --- a/packages/editor/src/components/block-list/layout.js +++ b/packages/editor/src/components/block-list/layout.js @@ -217,6 +217,7 @@ class BlockListLayout extends Component { blockRef={ this.setBlockRef } onSelectionStart={ this.onSelectionStart } onShiftSelection={ this.onShiftSelection } + onSelectionEnd={ this.onSelectionEnd } rootClientId={ rootClientId } layout={ defaultLayout } isFirst={ blockIndex === 0 }