mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04: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
|
// 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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');
|
||||||
|
Loading…
Reference in New Issue
Block a user