Skip to content

Commit

Permalink
block editor: try direct drag if no text selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 26, 2024
1 parent e349487 commit a72439c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
content: none !important;
}
}

img:not([draggable]) {
pointer-events: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {

return {
tabIndex: blockEditingMode === 'disabled' ? -1 : 0,
draggable: true,
...wrapperProps,
...props,
ref: mergedRefs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,25 @@ export function useEventHandlers( { clientId, isSelected } ) {
* @param {DragEvent} event Drag event.
*/
function onDragStart( event ) {
event.preventDefault();
const { ownerDocument } = node;
const { defaultView } = ownerDocument;
const selection = defaultView.getSelection();
if (
node !== event.target ||
node.contains( selection.anchorNode ) ||
node.contains( selection.focusNode )
) {
event.preventDefault();
return;
}
const data = JSON.stringify( {
type: 'block',
srcClientIds: [ clientId ],
srcRootClientId: getBlockRootClientId( clientId ),
} );
event.dataTransfer.clearData();
event.dataTransfer.setData( 'wp-blocks', data );
selection.removeAllRanges();
}

node.addEventListener( 'keydown', onKeyDown );
Expand Down

0 comments on commit a72439c

Please sign in to comment.