diff --git a/butterfly/static/ext.js b/butterfly/static/ext.js index b6e5256..67a78a6 100644 --- a/butterfly/static/ext.js +++ b/butterfly/static/ext.js @@ -142,11 +142,19 @@ }); addEventListener('paste', function(e) { - var data; + var data, send, size; butterfly.bell("pasted"); data = e.clipboardData.getData('text/plain'); data = data.replace(/\r\n/g, '\n').replace(/\n/g, '\r'); - butterfly.send(data); + size = 1024; + send = function() { + butterfly.send(data.substring(0, size)); + data = data.substring(size); + if (data.length) { + return setTimeout(send, 25); + } + }; + send(); return e.preventDefault(); }); diff --git a/coffees/ext/clipboard.coffee b/coffees/ext/clipboard.coffee index 845e820..b28167c 100644 --- a/coffees/ext/clipboard.coffee +++ b/coffees/ext/clipboard.coffee @@ -33,9 +33,18 @@ addEventListener 'copy', copy = (e) -> e.clipboardData.setData 'text/plain', data.slice(0, -1) e.preventDefault() + addEventListener 'paste', (e) -> butterfly.bell "pasted" data = e.clipboardData.getData 'text/plain' data = data.replace(/\r\n/g, '\n').replace(/\n/g, '\r') - butterfly.send data + # Send big data in chunks to prevent data loss + size = 1024 + send = -> + butterfly.send data.substring(0, size) + data = data.substring(size) + if data.length + setTimeout send, 25 + send() + e.preventDefault()