Make the dropdown widget's file drop a callback and keep stray file drops from navigating the browser away (#4553)

* Make the dropdown widget's file drop a callback and keep stray file drops from navigating the browser away

* Look up the dropped file's widget before reading the file
This commit is contained in:
Keavon Chambers
2026-09-19 16:01:58 -07:00
committed by GitHub
parent 97d8452a1d
commit 23e6b0f11d
10 changed files with 100 additions and 15 deletions
+17
View File
@@ -293,6 +293,23 @@ export function onPaste(e: ClipboardEvent, editor: EditorWrapper) {
});
}
// A spot that takes dropped files has canceled the event by the time it bubbles up to the window
function isUnclaimedFileDrag(e: DragEvent): boolean {
return !e.defaultPrevented && Boolean(e.dataTransfer?.types.includes("Files"));
}
export function onDragOver(e: DragEvent) {
if (!isUnclaimedFileDrag(e)) return;
// Refusing the drop here keeps the browser from navigating away to open the file
e.preventDefault();
if (e.dataTransfer) e.dataTransfer.dropEffect = "none";
}
export function onDrop(e: DragEvent) {
if (isUnclaimedFileDrag(e)) e.preventDefault();
}
export function onFocusOut() {
canvasFocused = false;
}