fix: prevent drag'n'drop from opening in browser when dropped in empty area of annotation guide editor#10343
Conversation
Refactor not found components to use a common handleReturn function for navigation.
Remove console log for history length in TaskNotFoundComponent.
Added a new 'Return to Previous Page' button with smart fallback navigation.
Updated link for 'Return to Previous Page' button feature.
Updated the link for the 'Return to Previous Page' button in the changelog.
…y area of annotation guide editor
zhiltsov-max
left a comment
There was a problem hiding this comment.
Hi, thank you for the PR. Please check the comments.
There was a problem hiding this comment.
I can see the fix allows dropping the file below the last line. But it also allows it in the preview area on the right side. I don't think drag'n'drop should work in the text preview area, only in the editor.
There was a problem hiding this comment.
Root cause of the drag'n'drop bug : the onDrop/onDragOver handlers were attached to cvat-guide-page-editor-wrapper, which wraps the entire MDEditor component — both the left editor pane and the right preview pane. There was no check to see where the drag event originated, so drops anywhere inside the wrapper (including the preview) were accepted.
Fix: in both the outer wrapper's onDrop/onDragOver and the MDEditor's own onDrop, use (event.target as HTMLElement).closest('.w-md-editor-preview') to detect whether the event originated in the preview pane. If it did, the handler returns early (for onDrop) or skips calling preventDefault() (for onDragOver), so the browser treats it as a regular unhandled drop and the file is not inserted. The guard is applied at both levels because MDEditor's onDrop prop bubbles across both panes.
There was a problem hiding this comment.
While checking the fix, I also found that there is a similar issue exists with the text editing cursor placement - you can't put a cursor in the text if clicking below the last line. The issue is very similar to the former one, I think it should be fixed in the same PR as well.
annotation_guide_cursor_placement-2026-03-09_19.43.22.mp4
There was a problem hiding this comment.
Root cause of the cursor placement below the last line: @uiw/react-md-editor auto-sizes its internal textarea to exactly fit the current content. When there are only 2 lines of text, the <textarea> element is only 2 lines tall. The surrounding .w-md-editor-text pane fills the visible editor height, but below the textarea is empty, non-interactive space — clicks there don't reach the <textarea>, so no cursor is placed.
Fix: added .w-md-editor-text { height: 100%; } inside .cvat-guide-page-editor-wrapper in styles.scss. This stretches the text pane to fill the full editor height. Because the textarea's auto-resize works relative to its container, it now expands to cover the full pane, meaning any click in the editor's left half lands on the textarea.
fix: prevent drag'n'drop files from opening in browser when dropped below editor text
Problem
In the annotation guide editor, drag-and-drop of image/file uploads only worked when the file was dropped directly onto the text content area of the
<textarea>. Dropping a file in the empty space below the last line of text — which is visually part of the editing area — caused the browser to open the file in a new tab instead of inserting it into the guide. The cursor correctly showed a+icon throughout the whole editor pane, which made the broken area hard to predict.Root Cause
The
onDrophandler was placed only on the<MDEditor>component, which propagates the event to its inner<textarea>. The<textarea>'s hit area ends at the last character of text. Any drop in the empty space below lands on the wrapper<div>, which had no handler, allowing the browser to process the drag event natively (i.e. navigate to the file URL).Solution
Added
onDropandonDragOver(withevent.preventDefault()) to thecvat-guide-page-editor-wrapperdiv. This intercepts drop events anywhere inside the editor's visible area and routes them to the existinghandleInsertFileslogic, which appends the files at the current cursor position (or end of text).
Changes
— added
onDragOverandonDrophandlers on the editor wrapper<div>.Testing steps
empty area below the content.
the text (not on the text itself).
to
/api/assets/<uuid>URLs) — the browser must not open the file in anew tab.
Test
Screencast.from.2026-03-09.01-38-26.webm
Related issue
Closes #10305 (extracted from #6536).