-
1. Re: Paste clipboard data to panel, not document
Niknab0417 Jan 8, 2018 8:25 PM (in response to Niknab0417)After more hunting around, I decided to try using the info in this post from last year, but I'm getting a "csInterface.registerKeyEventsInterest is not a function" error message, now.
var keyCodes = [ { "keyCode": 56, "ctrlKey": true } ]; csInterface.registerKeyEventsInterest(JSON.stringify(keyCodes)); $(window).keydown(function (e) { e.preventDefault(); if (e.keyCode == 56 && e.ctrlKey) { pasteImage(); } });
-
2. Re: Paste clipboard data to panel, not document
Niknab0417 Jan 15, 2018 5:31 PM (in response to Niknab0417)1 person found this helpfulIt turns out the Brackets extension builder plugin I used to start this project was using CEP 5. So, I was getting the "not a function" error message because registerKeyEventsInterest() wasn't in the CSInterface.js file I was using.
It started working after I updated the files (I can tell the pasteImage() function is being registered because the canvas.remove(introTxt); action is applied), but the content still isn't being pasted to the panel.
Edit (because I don't feel like making another comment):
Turns out the reason the function paste function wasn't working was because I removed an if-continue line from my code early on and forgot to put it back. The full paste function is this:
pasteImage = function (e) { var items = e.originalEvent.clipboardData.items; e.preventDefault(); e.stopPropagation(); canvas.remove(introTxt); //Loop through files for (var i = 0; i < items.length; i++) { if (items[i].type.indexOf('image') == -1) { continue; } var file = items[i], 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); } }; $(window).on('paste', pasteImage);
So, aside from an outdated plugin, most of the issues were user error. Well, that only took me 3 weeks to fix...
-
3. Re: Paste clipboard data to panel, not document
Trevorׅ Jan 15, 2018 11:20 PM (in response to Niknab0417)Congrats on finding and posting the solution.
Adding the extra comment in this case would have been preferable as it let's the forums "followers" know you got it sorted out.
(I was about to look into it now :-)