Skip to content

[DragAndDrop] Copy internal content with Ctrl-drag - #3428

Merged
Julia Roldi (juliaroldi) merged 6 commits into
masterfrom
u/juliaroldi/dra-ctrl
Aug 6, 2026
Merged

[DragAndDrop] Copy internal content with Ctrl-drag#3428
Julia Roldi (juliaroldi) merged 6 commits into
masterfrom
u/juliaroldi/dra-ctrl

Conversation

@juliaroldi

Copy link
Copy Markdown
Contributor

Summary

Update handleDroppedInternalContent so holding Ctrl during an internal drag-and-drop copies the selected content instead of deleting the original selection. Preserve the existing move behavior when Ctrl is not pressed, with regression coverage for both paths.

How to test

  1. Run yarn test:fast --testPathPattern=handleDroppedInternalContent.
  2. Select editor content and Ctrl-drag it to another location; verify the content remains at the original location and is copied to the drop location. Repeat without Ctrl and verify the content moves instead.

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

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://microsoft.github.io/roosterjs/pr-preview/pr-3428/

Built to branch gh-pages at 2026-08-05 15:00 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates internal drag-and-drop handling in roosterjs-content-model-plugins to support copy-on-drop when the user holds Ctrl during an internal drag operation, while keeping the existing move-on-drop behavior when Ctrl is not pressed.

Changes:

  • Update handleDroppedInternalContent to skip deleting the source selection when event.ctrlKey is true (copy behavior).
  • Preserve existing selection deletion + normalization behavior when Ctrl is not pressed (move behavior).
  • Add regression tests to verify deleteSelection is (not) invoked for Ctrl vs non-Ctrl drops.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/roosterjs-content-model-plugins/lib/dragAndDrop/utils/handleDroppedInternalContent.ts Adds Ctrl-modifier branching to support copy vs move behavior during internal drops.
packages/roosterjs-content-model-plugins/test/dragAndDrop/utils/handleDroppedInternalContentTest.ts Adds targeted unit coverage ensuring selection deletion occurs only for non-Ctrl drops.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (deleteSelection(model, [], context).deleteResult == 'range') {
normalizeContentModel(model);
if (!event.ctrlKey) {

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.

On Mac, should this be Meta key?


if (deleteSelection(model, [], context).deleteResult == 'range') {
normalizeContentModel(model);
if (!event.ctrlKey || !event.metaKey) {

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.

&&

@juliaroldi
Julia Roldi (juliaroldi) merged commit ed1a199 into master Aug 6, 2026
1 check 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.

3 participants