fix: don't crash on drop highlighted text onto canvas (#4890)

This commit is contained in:
Tom Milligan 2022-03-09 10:51:13 +00:00 committed by GitHub
parent 20de06ef50
commit 4d5f00ff08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -4932,7 +4932,7 @@ class App extends React.Component<AppProps, AppState> {
private handleAppOnDrop = async (event: React.DragEvent<HTMLDivElement>) => {
try {
const file = event.dataTransfer.files[0];
const file = event.dataTransfer.files.item(0);
if (isSupportedImageFile(file)) {
// first attempt to decode scene from the image if it's embedded
@ -5008,7 +5008,7 @@ class App extends React.Component<AppProps, AppState> {
return;
}
const file = event.dataTransfer?.files[0];
const file = event.dataTransfer?.files.item(0);
if (
file?.type === MIME_TYPES.excalidrawlib ||
file?.name?.endsWith(".excalidrawlib")
@ -5024,7 +5024,7 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ isLoading: false, errorMessage: error.message }),
);
// default: assume an Excalidraw file regardless of extension/MimeType
} else {
} else if (file) {
this.setState({ isLoading: true });
if (nativeFileSystemSupported) {
try {

View File

@ -213,9 +213,12 @@ export class API {
}
});
const files = [blob] as File[] & { item: (index: number) => File };
files.item = (index: number) => files[index];
Object.defineProperty(fileDropEvent, "dataTransfer", {
value: {
files: [blob],
files,
getData: (type: string) => {
if (type === blob.type) {
return text;