From 98af95a6ce033e45b7e65123456b8f23d69355f6 Mon Sep 17 00:00:00 2001 From: j433866 Date: Thu, 6 Jun 2019 10:26:16 +0100 Subject: [PATCH] Change pasting to keep cursor position. Move output scrolling to changeTab() instead of set() --- src/web/waiters/InputWaiter.mjs | 9 ++++++++- src/web/waiters/OutputWaiter.mjs | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/web/waiters/InputWaiter.mjs b/src/web/waiters/InputWaiter.mjs index 0cd13212..d471e8b8 100644 --- a/src/web/waiters/InputWaiter.mjs +++ b/src/web/waiters/InputWaiter.mjs @@ -699,7 +699,14 @@ class InputWaiter { // changing the value, so instead change it here ourselves // and manually fire inputChange() e.preventDefault(); - document.getElementById("input-text").value += pastedData; + const inputText = document.getElementById("input-text"); + const selStart = inputText.selectionStart; + const selEnd = inputText.selectionEnd; + const startVal = inputText.value.slice(0, selStart); + const endVal = inputText.value.slice(selEnd); + + inputText.value = startVal + pastedData + endVal; + inputText.setSelectionRange(selStart + pastedData.length, selStart + pastedData.length); this.debounceInputChange(e); } else { e.preventDefault(); diff --git a/src/web/waiters/OutputWaiter.mjs b/src/web/waiters/OutputWaiter.mjs index 9f922742..770f82ed 100755 --- a/src/web/waiters/OutputWaiter.mjs +++ b/src/web/waiters/OutputWaiter.mjs @@ -293,7 +293,6 @@ class OutputWaiter { inputHighlighter.display = "none"; outputText.value = output.error; - outputText.scroll(0, 0); outputHtml.innerHTML = ""; } else if (output.status === "baked" || output.status === "inactive") { document.querySelector("#output-loader .loading-msg").textContent = `Loading output ${inputNum}`; @@ -327,7 +326,6 @@ class OutputWaiter { outputText.value = ""; outputHtml.innerHTML = output.data.result; - outputHtml.scroll(0, 0); // Execute script sections scriptElements = outputHtml.querySelectorAll("script"); @@ -360,7 +358,6 @@ class OutputWaiter { inputHighlighter.display = "block"; outputText.value = Utils.printable(output.data.result, true); - outputText.scroll(0, 0); outputHtml.innerHTML = ""; lines = output.data.result.count("\n") + 1; @@ -745,6 +742,9 @@ class OutputWaiter { this.app.debounce(this.set, 50, "setOutput", this, [inputNum])(); + document.getElementById("output-html").scroll(0, 0); + document.getElementById("output-text").scroll(0, 0); + if (changeInput) { this.manager.input.changeTab(inputNum, false); }