whitespace fix

This commit is contained in:
Baipyrus 2022-06-06 16:59:58 +02:00
parent ba21919972
commit c6b210aab3
2 changed files with 13 additions and 14 deletions

View File

@ -2,7 +2,6 @@ body {
background-color: black; background-color: black;
font-family: 'Lucida Console'; font-family: 'Lucida Console';
font-size: large; font-size: large;
/* white-space: pre; */
} }
#cursor { #cursor {

View File

@ -8,15 +8,15 @@ document.addEventListener("keypress", e=>{
return; return;
let textbox = document.getElementById("input"); let textbox = document.getElementById("input");
const index = cursorPosition - startPosition; const index = cursorPosition - startPosition;
if (e.key == ' ' && (textbox.innerText[index-1] == ' ' || cursorPosition == startPosition)) if (e.key == ' ' && (textbox.textContent[index-1] == ' ' || cursorPosition == startPosition))
return; return;
if (index <= textbox.innerText.length-1) { if (index <= textbox.textContent.length-1) {
const text = textbox.innerText; const text = textbox.textContent;
const a = text.substring(0, index); const a = text.substring(0, index);
const b = text.substring(index, text.length); const b = text.substring(index, text.length);
textbox.innerText = a + e.key + b; textbox.textContent = a + e.key + b;
} else } else
textbox.innerText += e.key; textbox.textContent += e.key;
cursorPosition++; cursorPosition++;
updateCursor(); updateCursor();
}); });
@ -24,18 +24,18 @@ document.addEventListener("keypress", e=>{
document.addEventListener("keydown", e=>{ document.addEventListener("keydown", e=>{
let textbox = document.getElementById("input"); let textbox = document.getElementById("input");
const index = cursorPosition - startPosition; const index = cursorPosition - startPosition;
const text = textbox.innerText; const text = textbox.textContent;
switch (e.key) { switch (e.key) {
case "Backspace": case "Backspace":
// Ein Zeichen nach links löschen // Ein Zeichen nach links löschen
if (index == 0) if (index == 0)
return; return;
if (index <= textbox.innerText.length-1) { if (index <= textbox.textContent.length-1) {
const a = text.substring(0, index-1); const a = text.substring(0, index-1);
const b = text.substring(index, text.length); const b = text.substring(index, text.length);
textbox.innerText=a+b; textbox.textContent=a+b;
} else } else
textbox.innerText = text.substring(0,text.length-1); textbox.textContent = text.substring(0,text.length-1);
cursorPosition--; cursorPosition--;
updateCursor(); updateCursor();
break; break;
@ -48,18 +48,18 @@ document.addEventListener("keydown", e=>{
break; break;
case "ArrowRight": case "ArrowRight":
// Ein Zeichen nach reckts // Ein Zeichen nach reckts
if (index < textbox.innerText.length) { if (index < textbox.textContent.length) {
cursorPosition++; cursorPosition++;
updateCursor(); updateCursor();
} }
break; break;
case "Delete": case "Delete":
// Ein Zeichen nach rechts löschen // Ein Zeichen nach rechts löschen
if (index == 0 || index >= textbox.innerText.length) if (index == 0 || index >= textbox.textContent.length)
return; return;
const a = text.substring(0, index); const a = text.substring(0, index);
const b = text.substring(index+1, text.length); const b = text.substring(index+1, text.length);
textbox.innerText=a+b; textbox.textContent=a+b;
break; break;
case "Enter": case "Enter":
// Befehl absenden / Zeilenumbruch // Befehl absenden / Zeilenumbruch
@ -70,7 +70,7 @@ document.addEventListener("keydown", e=>{
const commandOutput = ""; const commandOutput = "";
parent.innerHTML += '<a style="color: lightgrey;">' + text + '</a><br>' + commandOutput + pretext; parent.innerHTML += '<a style="color: lightgrey;">' + text + '</a><br>' + commandOutput + pretext;
textbox.innerText = ""; textbox.textContent = "";
parent.appendChild(textbox); parent.appendChild(textbox);
cursorPosition = startPosition; cursorPosition = startPosition;
cursorYOffset++; cursorYOffset++;