Limit rate on paste

This commit is contained in:
Florian Mounier
2016-10-07 11:30:59 +02:00
parent 15ebdf6907
commit d0eb37765a
2 changed files with 20 additions and 3 deletions

View File

@@ -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();
});

View File

@@ -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()