From 145fba594937cee99ded20f86a7681c53e0be49b Mon Sep 17 00:00:00 2001 From: j433866 Date: Tue, 30 Apr 2019 11:48:01 +0100 Subject: [PATCH] Input pasting now works --- src/web/InputWaiter.mjs | 28 ++++++++++++++++++++++++++++ src/web/Manager.mjs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index bb64a785..9af1992d 100644 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -463,6 +463,34 @@ class InputWaiter { } // inputPaste + /** + * Handler for input paste events + * Checks that the size of the input is below the display limit, otherwise treats it as a file/blob + * + * @param {event} e + */ + inputPaste(e) { + const pastedData = e.clipboardData.getData("Text"); + if (pastedData.length < (this.app.options.ioDisplayThreshold * 1024)) { + // inputChange() was being fired before the input value + // was set, so add it here instead + e.preventDefault(); + document.getElementById("input-text").value += pastedData; + this.inputChange(e); + } else { + e.preventDefault(); + e.stopPropagation(); + + const file = new File([pastedData], "PastedData", { + type: "text/plain", + lastModified: Date.now() + }); + + this.loadUIFiles([file]); + return false; + } + } + /** * Handler for input dragover events. diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 83b316ee..74c0ce15 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -145,7 +145,7 @@ class Manager { // Input this.addMultiEventListener("#input-text", "keyup", this.input.inputChange, this.input); - // this.addMultiEventListener("#input-text", "paste", this.input.inputPaste, this.input); + this.addMultiEventListener("#input-text", "paste", this.input.inputPaste, this.input); document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app)); // document.getElementById("clr-io").addEventListener("click", this.input.clearAllIoClick.bind(this.input)); this.addListeners("#open-file,#open-folder", "change", this.input.inputOpen, this.input);