feat: added the ability to paste images onto the input tab

This commit is contained in:
Tobias Martine 2024-08-18 19:54:43 +02:00
parent d635cca210
commit c33d2c155a

View file

@ -151,6 +151,18 @@ class InputWaiter {
// Event handlers // Event handlers
EditorView.domEventHandlers({ EditorView.domEventHandlers({
paste(event, view) { paste(event, view) {
const clipboardData = event.clipboardData || window.clipboardData;
const items = clipboardData.items;
event.target.files = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type.indexOf("image") !== -1) {
const file = item.getAsFile();
event.target.files.push(file);
event.preventDefault(); // Prevent the default paste behavior
}
}
setTimeout(() => { setTimeout(() => {
self.afterPaste(event); self.afterPaste(event);
}); });
@ -917,6 +929,9 @@ class InputWaiter {
* @param {event} e * @param {event} e
*/ */
afterPaste(e) { afterPaste(e) {
if (e.target.files) {
this.loadUIFiles(e.target.files);
}
// If EOL has been fixed, skip this. // If EOL has been fixed, skip this.
if (this.eolState > 1) return; if (this.eolState > 1) return;