`;
}
}
} else {
- if (input !== wordsList[i]) {
+ if (input !== word) {
wordEl = `
`;
@@ -3416,12 +3426,12 @@ async function loadWordsHistory() {
}
let loop;
- if (input.length > wordsList[i].length) {
+ if (input.length > word.length) {
//input is longer - extra characters possible (loop over input)
loop = input.length;
} else {
//input is shorter or equal (loop over word list)
- loop = wordsList[i].length;
+ loop = word.length;
}
for (let c = 0; c < loop; c++) {
@@ -3439,26 +3449,26 @@ async function loadWordsHistory() {
) {
extraCorrected = "extraCorrected";
}
- if (wordsList[i][c] !== undefined) {
- if (input[c] === wordsList[i][c]) {
+ if (word[c] !== undefined) {
+ if (input[c] === word[c]) {
if (correctedChar === input[c] || correctedChar === undefined) {
- wordEl += ``;
+ wordEl += ``;
} else {
wordEl +=
`";
}
} else {
if (input[c] === currentInput) {
wordEl +=
- "
" + wordsList[i][c] + "";
+ `";
} else if (input[c] === undefined) {
- wordEl += "
" + wordsList[i][c] + "";
+ wordEl += "
" + word[c] + "";
} else {
wordEl +=
`";
}
}
@@ -3470,8 +3480,8 @@ async function loadWordsHistory() {
} catch (e) {
try {
wordEl = "
";
- for (let c = 0; c < wordsList[i].length; c++) {
- wordEl += "" + wordsList[i][c] + "";
+ for (let c = 0; c < word.length; c++) {
+ wordEl += "" + word[c] + "";
}
wordEl += "
";
} catch {}
@@ -3792,7 +3802,9 @@ function showCustomTextPopup() {
.css("opacity", 0)
.removeClass("hidden")
.animate({ opacity: 1 }, 100, () => {
- $("#customTextPopup textarea").val(customText.join(" "));
+ let newtext = customText.join(" ");
+ newtext = newtext.replace(/ \n /g,"\n");
+ $("#customTextPopup textarea").val(newtext);
$("#customTextPopup .wordcount input").val(customTextWordCount);
$("#customTextPopup textarea").focus();
});
@@ -3839,8 +3851,12 @@ $("#customTextPopup textarea").keypress((e) => {
$("#customTextPopup .button").click(() => {
let text = $("#customTextPopup textarea").val();
text = text.trim();
- text = text.replace(/[\n\r\t ]/gm, " ");
+ text = text.replace(/[\r\t]/gm, " ");
text = text.replace(/ +/gm, " ");
+ text = text.replace(/(\r\n)+/g,"\r\n");
+ text = text.replace(/(\n)+/g,"\n");
+ text = text.replace(/(\r)+/g,"\r");
+ text = text.replace(/( *(\r\n|\r|\n) *)/g," \n ");
if ($("#customTextPopup .typographyCheck input").prop("checked")) {
text = Misc.cleanTypographySymbols(text);
}
@@ -4583,9 +4599,13 @@ $(document).keydown(function (event) {
handleBackspace(event);
}
- //space
- if (event.key === " " || (activeFunBox == "58008" && event.key === "Enter")) {
- handleSpace(event);
+ if(event.key === "Enter" && activeFunBox === "58008"){
+ event.key = " ";
+ }
+
+ //space or enter
+ if (event.key === " " || event.key === "Enter"){
+ handleSpace(event, (event.key === "Enter" ? true : false));
}
handleAlpha(event);
@@ -4643,6 +4663,7 @@ function handleBackspace(event) {
inputHistory.length > 0 &&
currentWordElementIndex > 0
) {
+ //if nothing is inputted and its not the first word
if (
(inputHistory[currentWordIndex - 1] == wordsList[currentWordIndex - 1] &&
!config.freedomMode) ||
@@ -4664,6 +4685,9 @@ function handleBackspace(event) {
}
}
currentWordIndex--;
+ if(wordsList[currentWordIndex] === "\n"){
+ currentWordIndex--;
+ }
currentWordElementIndex--;
updateActiveElement();
updateWordElement(!config.blindMode);
@@ -4701,9 +4725,12 @@ function handleBackspace(event) {
updateCaretPosition();
}
-function handleSpace(event) {
+function handleSpace(event, isEnter) {
if (!testActive) return;
if (currentInput === "") return;
+ let nextWord = wordsList[currentWordIndex + 1];
+ // if ((isEnter && nextWord !== "\n") && (isEnter && activeFunBox !== "58008")) return;
+ // if (!isEnter && nextWord === "\n") return;
event.preventDefault();
let currentWord = wordsList[currentWordIndex];
if (activeFunBox === "layoutfluid" && config.mode !== "time") {
@@ -4721,7 +4748,8 @@ function handleSpace(event) {
}
if (config.blindMode) $("#words .word.active letter").addClass("correct");
dontInsertSpace = true;
- if (currentWord == currentInput) {
+ let correctSpaceEnter = ((isEnter && nextWord === "\n") || (!isEnter && nextWord !== "\n"));
+ if (currentWord == currentInput && correctSpaceEnter) {
//correct word
if (
paceCaret !== null &&
@@ -4762,7 +4790,7 @@ function handleSpace(event) {
}
accuracyStats.incorrect++;
let cil = currentInput.length;
- if (cil < wordsList[currentWordIndex].length) {
+ // if (cil <= wordsList[currentWordIndex].length) {
if (cil >= currentCorrected.length) {
currentCorrected += "_";
} else {
@@ -4771,14 +4799,14 @@ function handleSpace(event) {
"_" +
currentCorrected.substring(cil + 1);
}
- }
- if (config.stopOnError != "off") {
+ // }
+ if (config.stopOnError != "off" || !correctSpaceEnter) {
if (config.difficulty == "expert" || config.difficulty == "master") {
//failed due to diff when pressing space
failTest();
return;
}
- if (config.stopOnError == "word") {
+ if (config.stopOnError == "word" || !correctSpaceEnter) {
currentInput += " ";
updateWordElement(true);
updateCaretPosition();
@@ -4805,9 +4833,14 @@ function handleSpace(event) {
}
}
+
correctedHistory.push(currentCorrected);
currentCorrected = "";
+ if(nextWord === "\n"){
+ currentWordIndex++;
+ }
+
if (!config.showAllLines || config.mode == "time") {
let currentTop = Math.floor(
document.querySelectorAll("#words .word")[currentWordElementIndex - 1]