Updated both editors to ignore image paste if text data apparent

Designed to ignore image data when copying from a spreadsheet.
Fixes #987
This commit is contained in:
Dan Brown 2019-05-15 20:23:09 +01:00
parent d62d2384cb
commit 0ee9e5c4db
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 27 additions and 7 deletions

View File

@ -180,9 +180,20 @@ class MarkdownEditor {
// Handle image paste // Handle image paste
cm.on('paste', (cm, event) => { cm.on('paste', (cm, event) => {
if (!event.clipboardData || !event.clipboardData.items) return; const clipboardItems = event.clipboardData.items;
for (let i = 0; i < event.clipboardData.items.length; i++) { if (!event.clipboardData || !clipboardItems) return;
uploadImage(event.clipboardData.items[i].getAsFile());
// Don't handle if clipboard includes text content
for (let clipboardItem of clipboardItems) {
if (clipboardItem.type.includes('text/')) {
return;
}
}
for (let clipboardItem of clipboardItems) {
if (clipboardItem.type.includes("image")) {
uploadImage(clipboardItem.getAsFile());
}
} }
}); });

View File

@ -8,11 +8,20 @@ import DrawIO from "../services/drawio";
* @param editor * @param editor
*/ */
function editorPaste(event, editor, wysiwygComponent) { function editorPaste(event, editor, wysiwygComponent) {
if (!event.clipboardData || !event.clipboardData.items) return; const clipboardItems = event.clipboardData.items;
if (!event.clipboardData || !clipboardItems) return;
for (let clipboardItem of event.clipboardData.items) { // Don't handle if clipboard includes text content
if (clipboardItem.type.indexOf("image") === -1) continue; for (let clipboardItem of clipboardItems) {
event.preventDefault(); if (clipboardItem.type.includes('text/')) {
return;
}
}
for (let clipboardItem of clipboardItems) {
if (!clipboardItem.type.includes("image")) {
continue;
}
const id = "image-" + Math.random().toString(16).slice(2); const id = "image-" + Math.random().toString(16).slice(2);
const loadingImage = window.baseUrl('/loading.gif'); const loadingImage = window.baseUrl('/loading.gif');