mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-27 04:32:14 +00:00
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:
parent
d62d2384cb
commit
0ee9e5c4db
@ -180,9 +180,20 @@ class MarkdownEditor {
|
||||
|
||||
// Handle image paste
|
||||
cm.on('paste', (cm, event) => {
|
||||
if (!event.clipboardData || !event.clipboardData.items) return;
|
||||
for (let i = 0; i < event.clipboardData.items.length; i++) {
|
||||
uploadImage(event.clipboardData.items[i].getAsFile());
|
||||
const clipboardItems = event.clipboardData.items;
|
||||
if (!event.clipboardData || !clipboardItems) return;
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -8,11 +8,20 @@ import DrawIO from "../services/drawio";
|
||||
* @param editor
|
||||
*/
|
||||
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) {
|
||||
if (clipboardItem.type.indexOf("image") === -1) continue;
|
||||
event.preventDefault();
|
||||
// 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")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const id = "image-" + Math.random().toString(16).slice(2);
|
||||
const loadingImage = window.baseUrl('/loading.gif');
|
||||
|
Loading…
Reference in New Issue
Block a user