Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement image pasting in md editor #7387

Merged
14 changes: 9 additions & 5 deletions src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ export const FormikMarkdownField = ({
const clipboardData = event.clipboardData;
const items = clipboardData.items;

if (!items) {
return;
}
if (!items) return;
reactoholic marked this conversation as resolved.
Show resolved Hide resolved

const storageBucketId = storageConfig?.storageBucketId;

if (storageBucketId) {
let hasImage = false;

for (const item of items) {
if (item.type.startsWith('image/')) {
const file = item.getAsFile();
Expand All @@ -165,11 +165,15 @@ export const FormikMarkdownField = ({
});
};

reader.readAsDataURL(file);
event.preventDefault();
reader.readAsDataURL(file); // Read to trigger onLoad.
hasImage = true;
}
}
}

if (hasImage) {
event.preventDefault(); // Prevent default only if there's an image.
}
}
},
[storageConfig?.storageBucketId, uploadFile]
Expand Down