Paste clipboard data to panel, not document
I've set up a function to handle pasting images from the clipboard to a canvas element inside my extension. It works fine on sites like jsfiddle or codepen, but Photoshop CC hijacks the event instead and content gets pasted to the active document as a new layer - the default behavior.
I assume I need to add some sort of if statement to prevent the default action if the panel has focus, but I don't know how to go about doing that. I'm not even sure what library/platform/thing I should be using for this. I have tabs open for CEP, ExtendScript, and CSXSLibrary, and I'm not sure which of these I need in this case.
Here's the main.js paste function:
pasteImage = function (e) {
var items = e.originalEvent.clipboardData.items;
// 1885434740 = charIDToTypeID( "past" ) = paste
e.preventDefault();
e.stopPropagation();
canvas.remove(introTxt);
//Loop through files
for (var i = 0; i < items.length; i++) {
if (items.type.indexOf('image') == -1) {
var file = items,
//type = items.type,
imageData = file.getAsFile(),
URLobj = window.URL || window.webkitURL,
img = new Image();
img.src = URLobj.createObjectURL(imageData);
fabric.Image.fromURL(img.src, function (imgInst) {
imgInst.scaleToWidth(350);
canvas.add(imgInst).centerObject(imgInst);
imgInst.setCoords();
canvas.renderAll();
}, imgAttrs);
}
}
}
As sort of a Hail Mary, I added this to my jsx file:
function stopPaste() {
var doc = app.activeDocument;
doc.paste(false);
}
and this event listener back in main.js:
function pasteListener() {
if (canvas.is(':focus')) {
csInterface.evalScript('stopPaste()');
}
}
csInterface.addEventListener('PhotoshopCallback', pasteListener);
