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

Allow paste of images from internet in MD editor. #7653

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/core/ui/forms/MarkdownInput/MarkdownInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export const MarkdownInput = memo(
return true; // Image
}

if (clipboardData?.files?.length && clipboardData?.files[0].type.startsWith('image/')) {
bobbykolev marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

if (item.kind === 'string' && item.type === 'text/html') {
const htmlContent = clipboardData?.getData('text/html');
return htmlContent?.includes('<img') ?? false; // HTML tag with image
Expand Down Expand Up @@ -160,26 +164,22 @@ export const MarkdownInput = memo(
}

if (!imageProcessed && isImage) {
if (item.kind === 'file' && item.type.startsWith('image/')) {
const file = item.getAsFile();

if (file) {
const reader = new FileReader();

reader.onload = () => {
uploadFile({
variables: {
file,
uploadData: { storageBucketId, temporaryLocation },
},
});
};

reader.readAsDataURL(file);
imageProcessed = true;
}
} else if (item.kind === 'string' && item.type === 'text/html') {
imageProcessed = true; // HTML with images
const file = item.getAsFile();

if (file) {
const reader = new FileReader();

reader.onload = () => {
uploadFile({
variables: {
file,
uploadData: { storageBucketId, temporaryLocation },
},
});
};

reader.readAsDataURL(file);
imageProcessed = true;
}
}

Expand Down