Skip to content

[DragAndDrop] Support dropping internal content within the same editor - #3412

Merged
juliaroldi merged 8 commits into
masterfrom
u/juliaroldi/dnd-tables
Jul 29, 2026
Merged

[DragAndDrop] Support dropping internal content within the same editor#3412
juliaroldi merged 8 commits into
masterfrom
u/juliaroldi/dnd-tables

Conversation

@juliaroldi

@juliaroldi juliaroldi commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for dropping content within the same editor (internal drag-and-drop), gated behind the new HandleDropInternalContent experimental feature.

  • DragAndDropPlugin now tracks internal drags (internalDrag flag set on dragstart) and, on beforeDrop, routes internal drops to the new handleDroppedInternalContent handler while external drops continue through the renamed handleDroppedExternalContent (formerly handleDroppedContent).
  • handleDroppedInternalContent inserts the dragged content at the drop position using the Content Model: it resolves the drop point via getNodePositionFromEvent, clones and trims the current selection, deletes the original selection, then merges the cloned model at the insertion point and restores the selection across the newly inserted range.
  • Adds the HandleDropInternalContent value to the ExperimentalFeature type and wires it into the demo site's editor options and experimental features panel.

How to test

  1. Run the drag-and-drop unit tests:
    yarn test:fast --testPathPattern=dragAndDrop
    
  2. Manual: build the demo (yarn builddemo), enable the HandleDropInternalContent experimental feature, then select content in the editor and drag it to a different position within the same editor.
    • Before this change: internal drops were effectively no-ops (the internal drag flag was only cleared).
    • After this change: the dragged content is moved to the drop location and the moved content stays selected.

Add HandleDropInternalContent experimental feature so content dragged and dropped within the same editor is moved via the Content Model instead of pasted as HTML. Split handleDroppedContent into handleDroppedExternalContent and handleDroppedInternalContent, capturing the dragged model on dragstart and merging it at the drop position.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: cf3fc3cb-44b2-4b1c-8290-0da8393f2b5e
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-29 17:30 UTC

@juliaroldi
juliaroldi marked this pull request as ready for review July 23, 2026 16:31
Comment on lines +29 to +31
const range = doc.createRange();
range.setStart(domPosition.node, domPosition.offset);
range.collapse(true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems range is not used at all

this.isInternalDragging = true;
this.internalDrag = true;
if (this.editor?.isExperimentalFeatureEnabled('HandleDropInternalContent')) {
const model = editor.getContentModelCopy('disconnected');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful about the "disconnected" mode, make sure you test the case when selected content has entity, see after drop if the entity is correctly dropped and if the DOM element is still the same one

@juliaroldi
juliaroldi merged commit fb75ae6 into master Jul 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants