From b31625133790d1dfd239c93bf487d12d5b1f9e70 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 15 Aug 2020 20:36:51 +0100 Subject: [PATCH] changed stop on error to stop on letter and stop on word --- public/index.html | 29 ++++++++++++++++++++++----- public/js/commandline.js | 43 +++++++++++++++++++++++++++++++++------- public/js/script.js | 30 ++++++++++++++-------------- public/js/settings.js | 9 ++++++++- public/js/userconfig.js | 31 ++++++++++++++++++----------- 5 files changed, 102 insertions(+), 40 deletions(-) diff --git a/public/index.html b/public/index.html index ce9149193..ea7a4b938 100644 --- a/public/index.html +++ b/public/index.html @@ -1450,15 +1450,34 @@

stop on error

- When enabled, incorrect input will not be registered and words - need to be 100% correct to be able to move on to the next. + Letter mode will stop input when pressing any incorrect letters. + Word mode will not allow you to continue to the next word until + you correct all mistakes.
-
+
off
-
- on +
+ word +
+
+ letter
diff --git a/public/js/commandline.js b/public/js/commandline.js index 8ca9b9d8d..cf7ad3f10 100644 --- a/public/js/commandline.js +++ b/public/js/commandline.js @@ -60,6 +60,15 @@ let commands = { showCommandLine(); }, }, + { + id: "changeStopOnError", + display: "Change stop on error...", + subgroup: true, + exec: () => { + currentCommands.push(commandsStopOnError); + showCommandLine(); + }, + }, { id: "toggleSmoothCaret", display: "Toggle smooth caret", @@ -111,13 +120,6 @@ let commands = { toggleBlindMode(); }, }, - { - id: "toggleStopOnError", - display: "Toggle stop on error", - exec: () => { - toggleStopOnError(); - }, - }, { id: "toggleQuickEnd", display: "Toggle quick end", @@ -719,6 +721,33 @@ let commandsConfidenceMode = { ], }; +let commandsStopOnError = { + title: "Change stop on error...", + list: [ + { + id: "changeStopOnErrorOff", + display: "off", + exec: () => { + setStopOnError("off"); + }, + }, + { + id: "changeStopOnErrorLetter", + display: "letter", + exec: () => { + setStopOnError("letter"); + }, + }, + { + id: "changeStopOnErrorWord", + display: "word", + exec: () => { + setStopOnError("word"); + }, + }, + ], +}; + let commandsFontSize = { title: "Change font size...", list: [ diff --git a/public/js/script.js b/public/js/script.js index ab65a09db..67e5ccedd 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -2826,9 +2826,9 @@ function updateTestModesNotice() { ); } - if (config.stopOnError) { + if (config.stopOnError != "off") { $(".pageTest #testModesNotice").append( - `
stop on error
` + `
stop on ${config.stopOnError}
` ); } @@ -3397,7 +3397,7 @@ $(document).keypress(function (event) { currentKeypress.count++; currentKeypress.words.push(currentWordIndex); - if (config.stopOnError && !thisCharCorrect) { + if (config.stopOnError == "letter" && !thisCharCorrect) { if (config.difficulty == "master") { //failed due to master diff when pressing a key inputHistory.push(currentInput); @@ -3688,7 +3688,18 @@ $(document).keydown((event) => { } else { playErrorSound(); accuracyStats.incorrect++; - if (config.stopOnError) { + let cil = currentInput.length; + if (cil < wordsList[currentWordIndex].length) { + if (cil >= currentCorrected.length) { + currentCorrected += "_"; + } else { + currentCorrected = + currentCorrected.substring(0, cil) + + "_" + + currentCorrected.substring(cil + 1); + } + } + if (config.stopOnError != "off") { if (config.difficulty == "expert" || config.difficulty == "master") { //failed due to diff when pressing space inputHistory.push(currentInput); @@ -3704,17 +3715,6 @@ $(document).keydown((event) => { } return; } - let cil = currentInput.length; - if (cil < wordsList[currentWordIndex].length) { - if (cil >= currentCorrected.length) { - currentCorrected += "_"; - } else { - currentCorrected = - currentCorrected.substring(0, cil) + - "_" + - currentCorrected.substring(cil + 1); - } - } inputHistory.push(currentInput); highlightBadWord(currentWordElementIndex, !config.blindMode); currentInput = ""; diff --git a/public/js/settings.js b/public/js/settings.js index c90892b09..ae4c3caf9 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -133,6 +133,7 @@ settingsGroups.confidenceMode = new SettingsGroup( setConfidenceMode, () => { settingsGroups.freedomMode.updateButton(); + settingsGroups.stopOnError.updateButton(); } ); settingsGroups.blindMode = new SettingsGroup("blindMode", setBlindMode); @@ -150,8 +151,14 @@ settingsGroups.colorfulMode = new SettingsGroup( setColorfulMode ); settingsGroups.randomTheme = new SettingsGroup("randomTheme", setRandomTheme); -settingsGroups.stopOnError = new SettingsGroup("stopOnError", setStopOnError); settingsGroups.stopOnError = new SettingsGroup( + "stopOnError", + setStopOnError, + () => { + settingsGroups.confidenceMode.updateButton(); + } +); +settingsGroups.playSoundOnError = new SettingsGroup( "playSoundOnError", setPlaySoundOnError ); diff --git a/public/js/userconfig.js b/public/js/userconfig.js index 98601d713..4ef3373d8 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -37,7 +37,7 @@ let defaultConfig = { randomTheme: false, timerColor: "black", timerOpacity: "0.25", - stopOnError: false, + stopOnError: "off", showAllLines: false, keymapMode: "off", keymapStyle: "staggered", @@ -162,6 +162,7 @@ function applyConfig(configObj) { setAlwaysShowDecimalPlaces(config.alwaysShowDecimalPlaces, true); setAlwaysShowWordsHistory(config.alwaysShowWordsHistory, true); setPlaySoundOnError(config.playSoundOnError, true); + setStopOnError(config.stopOnError, true); // if ( // configObj.resultFilters !== null && // configObj.resultFilters !== undefined @@ -175,6 +176,7 @@ function applyConfig(configObj) { config[configKey] = defaultConfig[configKey]; } }); + updateTestModesNotice(); } function loadActiveTagsFromCookie() { @@ -246,21 +248,24 @@ function setBlindMode(blind, nosave) { } //stoponerror -function toggleStopOnError() { - soe = !config.stopOnError; - if (soe == undefined) { - soe = false; - } - config.stopOnError = soe; - updateTestModesNotice(); - saveConfigToCookie(); -} +// function toggleStopOnError() { +// soe = !config.stopOnError; +// if (soe == undefined) { +// soe = false; +// } +// config.stopOnError = soe; +// updateTestModesNotice(); +// saveConfigToCookie(); +// } function setStopOnError(soe, nosave) { if (soe == undefined) { - soe = false; + soe = "off"; } config.stopOnError = soe; + if (config.stopOnError !== "off") { + config.confidenceMode = "off"; + } updateTestModesNotice(); if (!nosave) saveConfigToCookie(); } @@ -601,9 +606,11 @@ function setConfidenceMode(cm, nosave) { cm = "off"; } config.confidenceMode = cm; - if (config.freedomMode && config.confidenceMode !== "off") { + if (config.confidenceMode !== "off") { config.freedomMode = false; + config.stopOnError = "off"; } + updateTestModesNotice(); if (!nosave) saveConfigToCookie(); }