diff --git a/static/js/script.js b/static/js/script.js
index 04cb3fd..59d3c93 100644
--- a/static/js/script.js
+++ b/static/js/script.js
@@ -116,28 +116,31 @@ document.addEventListener('DOMContentLoaded', function() {
const targetElement = document.getElementById('target-text');
let highlightedText = '';
- for (let i = 0; i < currentText.length; i++) {
+ // Entferne führende und nachfolgende Leerzeichen aus dem aktuellen Text für die Anzeige
+ const trimmedText = currentText.trim();
+
+ for (let i = 0; i < trimmedText.length; i++) {
if (i < userInput.length) {
- if (userInput[i] === currentText[i]) {
+ if (userInput[i] === trimmedText[i]) {
// Für korrekt getippte Leerzeichen und Tabulatoren: sichtbar machen
- if (currentText[i] === ' ') {
+ if (trimmedText[i] === ' ') {
highlightedText += '·';
- } else if (currentText[i] === '\t') {
+ } else if (trimmedText[i] === '\t') {
highlightedText += '→';
} else {
- highlightedText += `${currentText[i]}`;
+ highlightedText += `${trimmedText[i]}`;
}
} else {
- highlightedText += `${currentText[i]}`;
+ highlightedText += `${trimmedText[i]}`;
}
} else {
// Für nicht eingegebene Zeichen: Einrückungen anzeigen
- if (currentText[i] === ' ') {
+ if (trimmedText[i] === ' ') {
highlightedText += '·';
- } else if (currentText[i] === '\t') {
+ } else if (trimmedText[i] === '\t') {
highlightedText += '→';
} else {
- highlightedText += currentText[i];
+ highlightedText += trimmedText[i];
}
}
}