Open sinedied opened 7 years ago
I have the same problem, How did you solve it?
I did not solve the issue unfortunately ðŸ˜
It is still open! I solved like this:
navigator.clipboard.read().then((data) => {
for (let i = 0; i < data.length; i++) {
if (data[i].types.includes("image/png")) {
data[i].getType("image/png").then((blob) => {
var img = document.createElement('img');
img.src = URL.createObjectURL(blob);
document.getElementById('body').appendChild(img);
});
}
}
});```
the only problem i have ace_editor.on('paster' ... runs 2 times paste function
This indeed seems like a useful addition, where based on the paste event you could upload the image data, and for example return a markdown syntax.
I see that currently image paste events are ignored in the onPaste code. So the above workaround would not work. I do wonder whether changing the behavior might break people's implementation, especially if they are using a the 'text' value from paste but are receiving null.
Compared to other feature requests/bugs, I label this as a p2 request, as it would not be essential for a code editor and be more of a nice addition.
Why not allow a function to override. For example if function onPasteOverride
exists run the function otherwise runs default code
the new onPaste
function would be:
var onPaste = function(e) {
var data = handleClipboardData(e);
if (clipboard.pasteCancelled())
return;
if (typeof onPasteOverride == "function") {
onPasteOverride(data);
return;
}
if (typeof data == "string") {
if (data)
host.onPaste(data, e);
if (useragent.isIE)
setTimeout(resetSelection);
event.preventDefault(e);
}
else {
text.value = "";
pasted = true;
}
};
or maybe to have this as an option to set like:
editor.setOnPasteOverride('functionname');
Hello @whazor, is there any progress on this topic?
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
Hello,
This issue is still relevant. Please reopen it.
Best regards, Petar
Hi, what would be the advantage of using an such event dispatched from editor, instead of directly using
editor.container.addEventListener("paste", function(e) {
})
@nightwing adding the event listener to the container
seems sufficient for now. I always find it hard to find out which is the correct element to attach listeners to. You can close this issue then.
From what I have read in the docs and tested, it is currently not possible to catch the "paste" event anything other than text, am I correct?
If so, how can I register event for catching for example pasted images on editor, to perform special processing on it? Is there a way or the
onPaste
function of the editor must be updated to support this?Thanks for your help!