Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow text to be dragged in and out of blocks #9241

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down