Skip to content
Open
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
17 changes: 10 additions & 7 deletions src/editor/attachments/drag_and_drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,18 @@ export class AttachmentDragAndDrop {
if (!targetNode || !$isActionTextAttachmentNode(targetNode)) return
if (draggedNode.is(targetNode)) return

// Resolve the gallery before detaching: the drop target matches any
// previewable attachment, but galleries only accept images, so removing
// first deleted PDFs and videos dropped onto another attachment.
const gallery = $findOrCreateGalleryForImage(targetNode)
if (!gallery) return

draggedNode.remove()

const gallery = $findOrCreateGalleryForImage(targetNode)
if (gallery) {
if (position === "before") {
targetNode.insertBefore(draggedNode)
} else {
targetNode.insertAfter(draggedNode)
}
if (position === "before") {
targetNode.insertBefore(draggedNode)
} else {
targetNode.insertAfter(draggedNode)
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/browser/tests/attachments/attachment_drag_and_drop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ test.describe("Attachment Drag and Drop", () => {

await assertGalleryWithImages(editor, 3)
})

test("drag a previewable non-image onto another keeps both", async ({ page, editor }) => {
await editor.uploadFile("test/fixtures/files/dummy.pdf")
await editor.send("Enter")
await editor.uploadFile("test/fixtures/files/dummy.pdf")
await waitForUploadsComplete(page, editor)
await expect(page.locator("figure.attachment")).toHaveCount(2)

await simulateDragByIndex(page, 1, 0, "onto")
await editor.flush()

// Galleries only take images, so this drop cannot be honoured. It should
// leave the document alone rather than swallow the dragged attachment.
await assertNoGallery(page)
await expect(page.locator("figure.attachment")).toHaveCount(2)
})
})

test.describe("Within-gallery reorder", () => {
Expand Down
Loading