mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #5056 from gorenje/master
Support text drag & drop into markdown editor
This commit is contained in:
commit
71f8de94b0
@ -27,6 +27,12 @@
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
function file2Text(file,cb) {
|
||||
file.arrayBuffer().then(d => {
|
||||
cb( new TextDecoder().decode(d) )
|
||||
}).catch(ex => { cb(`error: ${ex}`) })
|
||||
}
|
||||
|
||||
var initialized = false;
|
||||
var currentEditor = null;
|
||||
/**
|
||||
@ -52,7 +58,8 @@
|
||||
if (files.length === 1) {
|
||||
var file = files[0];
|
||||
var name = file.name.toLowerCase();
|
||||
|
||||
var fileType = file.type.toLowerCase();
|
||||
|
||||
if (name.match(/\.(apng|avif|gif|jpeg|png|svg|webp)$/)) {
|
||||
file2base64Image(file, function (image) {
|
||||
var session = currentEditor.getSession();
|
||||
@ -63,7 +70,30 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ( fileType.startsWith("text/") ) {
|
||||
file2Text(file, function (txt) {
|
||||
var session = currentEditor.getSession();
|
||||
var pos = session.getCursorPosition();
|
||||
session.insert(pos, txt);
|
||||
$("#red-ui-image-drop-target").hide();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
} else if ($.inArray("text/plain", ev.originalEvent.dataTransfer.types) != -1) {
|
||||
let item = Object.values(ev.originalEvent.dataTransfer.items).filter(d => d.type == "text/plain")[0]
|
||||
|
||||
if (item) {
|
||||
item.getAsString(txt => {
|
||||
var session = currentEditor.getSession();
|
||||
var pos = session.getCursorPosition();
|
||||
session.insert(pos, txt);
|
||||
$("#red-ui-image-drop-target").hide();
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
$("#red-ui-image-drop-target").hide();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user