changed stop on error to stop on letter and stop on word

This commit is contained in:
Jack 2020-08-15 20:36:51 +01:00
parent 48274c9df2
commit b316251337
5 changed files with 102 additions and 40 deletions

View file

@ -1450,15 +1450,34 @@
<div class="section stopOnError">
<h1>stop on error</h1>
<div class="text">
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.
</div>
<div class="buttons">
<div class="button off" tabindex="0" onclick="this.blur();">
<div
class="button"
stopOnError="off"
tabindex="0"
onclick="this.blur();"
>
off
</div>
<div class="button on" tabindex="0" onclick="this.blur();">
on
<div
class="button"
stopOnError="word"
tabindex="0"
onclick="this.blur();"
>
word
</div>
<div
class="button"
stopOnError="letter"
tabindex="0"
onclick="this.blur();"
>
letter
</div>
</div>
</div>

View file

@ -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: [

View file

@ -2826,9 +2826,9 @@ function updateTestModesNotice() {
);
}
if (config.stopOnError) {
if (config.stopOnError != "off") {
$(".pageTest #testModesNotice").append(
`<div><i class="fas fa-hand-paper"></i>stop on error</div>`
`<div><i class="fas fa-hand-paper"></i>stop on ${config.stopOnError}</div>`
);
}
@ -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 = "";

View file

@ -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
);

View file

@ -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();
}