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

This commit is contained in:
Tobias Martine 2024-08-18 19:16:00 +02:00
parent d635cca210
commit 3c40137c2d

View file

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