From 8e7e6cf3965318a022e4edf05bd1fa88c7e753b5 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Thu, 2 Oct 2014 16:41:43 -0400 Subject: [PATCH] Copy and Paste between instances of jspaint --- README.md | 5 ++--- src/app.js | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 17024a5..3127e04 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,8 @@ You can also install it as a chrome app. * [A lot of stuff](TODO.md) One thing that may not be doable is full clipboard support. -You can paste with Ctrl+V, but you can't copy or cut, and you can't use the menu items. -After all, it would be terrible if web pages were able to access your clipboard at will... -It would be nice if web pages could *request* it, though! +You can copy with Ctrl+C, cut with Ctrl+X, and paste with Ctrl+V, +but copied data can only be pasted into other instances of jspaint, and you can't use the menu items. ## Staying True to the Original diff --git a/src/app.js b/src/app.js index d953f6c..95c2876 100644 --- a/src/app.js +++ b/src/app.js @@ -292,9 +292,10 @@ $G.on("cut copy paste", function(e){ if(e.type === "copy" || e.type === "cut"){ if(selection && selection.canvas){ - var data = selection.canvas.toDataURL("image/png"); - cd.setData("URL", data); - cd.setData("image/png", data); + var data_url = selection.canvas.toDataURL(); + cd.setData("text/x-data-uri; type=image/png", data_url); + cd.setData("text/uri-list", data_url); + cd.setData("URL", data_url); if(e.type === "cut"){ selection.destroy(); selection = null; @@ -302,9 +303,18 @@ $G.on("cut copy paste", function(e){ } }else if(e.type === "paste"){ $.each(cd.items, function(i, item){ - if(item.type.match(/image/)){ + if(item.type.match(/^text\/(?:x-data-)?uri/)){ + item.getAsString(function(str){ + var img = E("img"); + img.onload = function(){ + paste(img); + }; + img.src = str; + }); + return false; // break $.each + }else if(item.type.match(/^image/)){ paste_file(item.getAsFile()); - return false; + return false; // break $.each } }); }