Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(md): drag insert indicator not disappearing on image drop (#5055)
Peter Chinman90d5a006a434
diff --git a/apps/web/src/features/block-md/component/MarkdownEditor.tsx b/apps/web/src/features/block-md/component/MarkdownEditor.tsxindex 698c5a6657..b1621d3bca 100644--- a/apps/web/src/features/block-md/component/MarkdownEditor.tsx+++ b/apps/web/src/features/block-md/component/MarkdownEditor.tsx@@ -426,6 +426,9 @@ export function MarkdownEditor(props: {}, 60);onDragEnd((event: EntityDragEvent) => {+ // dndDragMove is a trailing throttle, so a callback scheduled just before+ // the drop would otherwise fire after it and could re-show the indicator.+ dndDragMove.clear();// Only soup entity drags insert mentions (not e.g. sidebar favorite drags).if (event.draggable?.data.dragType !== 'entity') return;dndDragEnd(event);diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/drag-insert/dragInsertPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/drag-insert/dragInsertPlugin.tsindex 9c838b591b..890416a7c3 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/drag-insert/dragInsertPlugin.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/drag-insert/dragInsertPlugin.ts@@ -37,7 +37,9 @@ export const createDragInsertStore = () => {* @param onDragLeave - Called when a drag leave occurs.* @param onDragEnd - Called when a drag end occurs.* @param collisionPadding - The amount of padding to add to the elements when- * calculating the insertion point.+ * calculating the insertion point. Defaults to 8, matching the padding+ * used by the drop-position helpers in utils/fileUploadUtils.ts and+ * utils/dragInsertUtils.ts so the preview agrees with the insertion.* @param setState - A DragInsertState store to recive the state of the* dragging. Can be passed to the DragInsertIndicator component.* @param dragListenerRef - A ref to a div that will listen for drag events.@@ -59,6 +61,8 @@ type DragInsertPluginProps = {export type InsertionMarker = 'before' | 'after';+const DEFAULT_COLLISION_PADDING = 8;+export const SET_SELECTION_AT_INSERTION: LexicalCommand<[NodeKey, InsertionMarker]> = createCommand('SET_SELECTION_AT_INSERTION');@@ -101,6 +105,9 @@ export function calculateInsertPoint(const root = $getRoot();const children = root.getChildren();+ if (children.length === 0) {+ return { key: null, position: null, domRect: null };+ }const firstRect = elementKeyToDomRect(editor, children[0].getKey());if (firstRect && event.clientY < firstRect.top) {@@ -161,15 +168,23 @@ function registerDragInsert(editor: LexicalEditor,props: DragInsertPluginProps) {+ const collisionPadding = props.collisionPadding ?? DEFAULT_COLLISION_PADDING;+const handleDragOver = (event: DragEvent) => {event.preventDefault();const { key, position } = calculateInsertPoint(editor,event,- props.collisionPadding+ collisionPadding);if (!key || !position) {+ // No insert point under the cursor (e.g. a gap between blocks): hide the+ // preview instead of leaving it frozen at the last valid position, which+ // no longer matches where a drop would insert.+ if (props.setState) {+ props.setState({ visible: false });+ }return;}@@ -184,19 +199,23 @@ function registerDragInsert(const handleDrop = (event: DragEvent) => {event.preventDefault();+ // Always hide the preview, even when the drop point resolves to no valid+ // insert position. Drags that originate outside this editor (OS files,+ // images dragged from other components) never fire dragend/dragleave here+ // after the drop, so this is the last chance to clear the indicator.+ if (props.setState) {+ props.setState({ visible: false });+ }+const { key, position } = calculateInsertPoint(editor,event,- props.collisionPadding+ collisionPadding);if (!key || !position) {return;}- if (props.setState) {- props.setState({ visible: false });- }-if (props.onDrop) {editor.dispatchCommand(SET_SELECTION_AT_INSERTION, [key, position]);props.onDrop(key, position, event);