Fix jumping between boxes

This commit is contained in:
Matthias 2020-09-06 00:12:14 -04:00
parent 9ce2e08810
commit 1201803168
1 changed files with 5 additions and 4 deletions

View File

@ -18,13 +18,14 @@
<script>
const textEl = document.getElementById("text");
const textExtEl = document.getElementById("extended_text");
textEl.addEventListener("keypressed", evt => {
textEl.addEventListener("keydown", evt => {
// If the length is more than 120
const value = textEl.value;
if (value.length > 120) {
const toMove = value.substring(value.lastIndexOf(" ") + 1); //Plus 1 trims the space
if (value.length > 140) {
const splitAt = value.lastIndexOf(" ", 140) + 1; // Plus 1 keeps the space in the original text instead of moving it
const toMove = value.substring(splitAt);
textExtEl.value = toMove + textExtEl.value;
textEl.value = value.substring(0, value.lastIndexOf(" ") + 1)// Plus 1 keeps the space
textEl.value = value.substring(0, splitAt);
}
});