From 628615f9bc637919bb458a8bc55b676edc2fa7ac Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 15 Aug 2026 20:23:30 -0400 Subject: [PATCH] fix: Dragging text within an image caption corrupts the document (#13449) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The caption is editable DOM outside of the document, so ProseMirror handled the drag against the document selection instead — moving unrelated content and throwing a mismatched transaction as the caption commit landed mid-dispatch. Fixes OUTLINE-CLOUD-AB8 --- shared/editor/components/Caption.tsx | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/shared/editor/components/Caption.tsx b/shared/editor/components/Caption.tsx index 9aab9c480c..8a45d866f1 100644 --- a/shared/editor/components/Caption.tsx +++ b/shared/editor/components/Caption.tsx @@ -1,6 +1,7 @@ import * as React from "react"; import styled from "styled-components"; import { s } from "../../styles"; +import { getDataTransferFiles } from "../../utils/files"; import { EditorStyleHelper } from "../styles/EditorStyleHelper"; import { useTranslation } from "react-i18next"; @@ -32,6 +33,34 @@ function Caption({ ...rest }: Props) { const { t } = useTranslation(); + const ref = React.useRef(null); + + // The caption is not part of the document, so drags within it must not reach + // the editor, which would act on the document selection instead. Native + // listeners are used because they run before the editor's, React's do not. + React.useEffect(() => { + const element = ref.current; + if (!element) { + return; + } + + const handleDrag = (event: DragEvent) => { + // File drops are left alone so that they still upload. + if (getDataTransferFiles(event).length) { + return; + } + event.stopPropagation(); + }; + + element.addEventListener("dragstart", handleDrag); + element.addEventListener("drop", handleDrag); + + return () => { + element.removeEventListener("dragstart", handleDrag); + element.removeEventListener("drop", handleDrag); + }; + }, []); + const handlePaste = (event: React.ClipboardEvent) => { event.preventDefault(); const text = event.clipboardData.getData("text/plain"); @@ -60,6 +89,7 @@ function Caption({ return (