diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index c3e3b2566..3e391fa63 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -234,6 +234,19 @@ define([ editor.scrollIntoView(cursor); }); + // Don't paste file path in the users wants to paste a file + editor.on('paste', function (editor, ev) { + try { + if (!ev.clipboardData.items) { return; } + var items = Array.prototype.slice.apply(ev.clipboardData.items); + var hasFile = items.some(function (el) { + return el.kind === "file"; + }); + if (!hasFile) { return; } + ev.preventDefault(); + } catch (e) { console.error(e); } + }); + var setMode = exp.setMode = function (mode, cb) { exp.highlightMode = mode; if (mode === 'markdown') { mode = 'gfm'; } diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 90ca5e256..f7a1c17ff 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -528,6 +528,26 @@ define([ $hoverArea.removeClass('cp-fileupload-hovering'); onFileDrop(dropped, e); }); + + + // Upload files on paste + $area.on('paste', function (e) { + try { + var ev = e.originalEvent; + if (!ev.clipboardData.items) { return; } + var items = Array.prototype.slice.apply(ev.clipboardData.items); + var hasFile = items.some(function (el) { + return el.kind === "file"; + }); + if (!hasFile) { return; } + ev.preventDefault(); + items.forEach(function (el) { + if (el.kind !== "file") { return; } + var file = el.getAsFile(); + handleFile(file, e); + }); + } catch (e) { console.error(e); } + }); }; var createCkeditorDropHandler = function () { var editor = config.ckeditor;