Skip to content

Commit 83c6dc4

Browse files
committed
Refactor handle_drag_over to ensure the drag range reference is checked before attempting to update the selection
1 parent c25adf3 commit 83c6dc4

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/hooks/use-drag-drop.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ export const use_drag_drop = ({
6262

6363
const handle_drag_over = (e: React.DragEvent<HTMLDivElement>) => {
6464
e.preventDefault()
65+
66+
if (!dragged_text_range_ref.current) {
67+
return
68+
}
69+
70+
const range = document.caretRangeFromPoint(e.clientX, e.clientY)
71+
if (range && input_ref.current?.contains(range.startContainer)) {
72+
const selection = window.getSelection()
73+
if (selection) {
74+
selection.removeAllRanges()
75+
selection.addRange(range)
76+
}
77+
}
6578
}
6679

6780
const handle_drop = (e: React.DragEvent<HTMLDivElement>) => {

0 commit comments

Comments
 (0)