Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions frontend/src/ts/input/helpers/word-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export async function goToNextWord({

PaceCaret.handleSpace(correctInsert, TestWords.words.getCurrentText());

Funbox.toggleScript(TestWords.words.getText(TestState.activeWordIndex + 1));
const nextWord = TestWords.words.getText(TestState.activeWordIndex + 1);
if (nextWord !== undefined) Funbox.toggleScript(nextWord);

const lastWord = TestState.activeWordIndex >= TestWords.words.length - 1;
if (lastWord) {
Expand Down Expand Up @@ -97,7 +98,8 @@ export function goToPreviousWord(

TestState.decreaseActiveWordIndex();

Funbox.toggleScript(TestWords.words.getText(TestState.activeWordIndex));
const word = TestWords.words.getText(TestState.activeWordIndex);
if (word !== undefined) Funbox.toggleScript(word);

const nospaceEnabled = isFunboxActiveWithProperty("nospace");

Expand Down
8 changes: 6 additions & 2 deletions frontend/src/ts/test/british-english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { capitalizeFirstLetterOfEachWord } from "../utils/strings";

export async function replace(
word: string,
previousWord: string,
previousWord: string | undefined,
): Promise<string> {
// Convert American-style double quotes to British-style single quotes
if (word.includes('"')) {
Expand Down Expand Up @@ -38,7 +38,11 @@ export async function replace(
? [rule, []]
: [rule.britishWord, rule.exceptPreviousWords];

if (Config.mode === "quote" && exceptions.includes(previousWord)) {
if (
Config.mode === "quote" &&
previousWord !== undefined &&
exceptions.includes(previousWord)
) {
return word;
}

Expand Down
10 changes: 7 additions & 3 deletions frontend/src/ts/test/pace-caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ function incrementLetterIndex(): void {
settings.currentLetterIndex++;
if (
settings.currentLetterIndex >=
TestWords.words.getText(settings.currentWordIndex).length + 1
// oxlint-disable-next-line typescript/no-non-null-assertion let it throw if undefined
Comment thread
Miodec marked this conversation as resolved.
Comment thread
Miodec marked this conversation as resolved.
TestWords.words.getText(settings.currentWordIndex)!.length + 1
) {
Comment thread
Miodec marked this conversation as resolved.
//go to the next word
settings.currentLetterIndex = 0;
Expand All @@ -193,7 +194,9 @@ function incrementLetterIndex(): void {
if (settings.currentLetterIndex <= -2) {
//go to the previous word
settings.currentLetterIndex =
TestWords.words.getText(settings.currentWordIndex - 1).length - 1;
// oxlint-disable-next-line typescript/no-non-null-assertion let it throw if undefined
Comment thread
Miodec marked this conversation as resolved.
Comment thread
Miodec marked this conversation as resolved.
TestWords.words.getText(settings.currentWordIndex - 1)!.length -
1;
settings.currentWordIndex--;
}
settings.correction++;
Expand All @@ -203,7 +206,8 @@ function incrementLetterIndex(): void {
settings.currentLetterIndex++;
if (
settings.currentLetterIndex >=
TestWords.words.getText(settings.currentWordIndex).length
// oxlint-disable-next-line typescript/no-non-null-assertion let it throw if undefined
Comment thread
Miodec marked this conversation as resolved.
Comment thread
Miodec marked this conversation as resolved.
TestWords.words.getText(settings.currentWordIndex)!.length
) {
Comment thread
Miodec marked this conversation as resolved.
//go to the next word
settings.currentLetterIndex = 0;
Expand Down
17 changes: 8 additions & 9 deletions frontend/src/ts/test/practise-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ export function init(
if (missed === "biwords") {
for (let i = 0; i < TestWords.words.length; i++) {
const missedWord = TestWords.words.getText(i);

if (missedWord === undefined) continue; // won't happen, but ts complains

const missedWordCount = missedWords[missedWord];
if (missedWordCount !== undefined) {
if (i === 0) {
sortableMissedBiwords.push([missedWord, "", missedWordCount]);
} else {
sortableMissedBiwords.push([
missedWord,
TestWords.words.getText(i - 1),
missedWordCount,
]);
}
sortableMissedBiwords.push([
missedWord,
TestWords.words.getText(i - 1) ?? "",
missedWordCount,
]);
}
}
sortableMissedBiwords.sort((a, b) => {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,9 @@ export async function finish(difficultyFailed = false): Promise<void> {

const lastWordInputLength = history[wordIndex]?.length ?? 0;

if (lastWordInputLength < TestWords.words.getText(wordIndex).length) {
if (
lastWordInputLength < (TestWords.words.getText(wordIndex)?.length ?? 0)
) {
historyLength--;
}

Expand Down
10 changes: 6 additions & 4 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ function showWords(): void {
} else {
let wordsHTML = "";
for (let i = 0; i < TestWords.words.length; i++) {
wordsHTML += buildWordHTML(TestWords.words.getText(i), i);
const word = TestWords.words.getText(i);
if (word === undefined) continue; // won't happen, but ts complains
wordsHTML += buildWordHTML(word, i);
}
wordsEl.setHtml(wordsHTML);
}
Expand Down Expand Up @@ -737,7 +739,7 @@ export async function updateWordLetters({
async () => {
pendingWordData.delete(wordIndex);
const currentWord = TestWords.words.getText(wordIndex);
if (!currentWord && Config.mode !== "zen") return;
if (currentWord === undefined && Config.mode !== "zen") return;
let ret = "";
const wordAtIndex = getWordElement(wordIndex);
if (!wordAtIndex) return;
Expand Down Expand Up @@ -767,7 +769,7 @@ export async function updateWordLetters({
const funbox = findSingleActiveFunboxWithFunction("getWordHtml");

const inputChars = Strings.splitIntoCharacters(input);
const currentWordChars = Strings.splitIntoCharacters(currentWord);
const currentWordChars = Strings.splitIntoCharacters(currentWord ?? "");
for (let i = 0; i < inputChars.length; i++) {
const charCorrect = currentWordChars[i] === inputChars[i];

Expand Down Expand Up @@ -867,7 +869,7 @@ export async function updateWordLetters({
hintsHtml = createHintsHtml(
hintIndices,
wordAtIndexLetters,
currentWord,
currentWord ?? "",
);
} else {
hintsHtml = createHintsHtml(hintIndices, wordAtIndexLetters, input);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/test/test-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Words {
}

getText(i?: undefined, raw?: boolean): string[];
getText(i: number, raw?: boolean): string;
getText(i: number, raw?: boolean): string | undefined;
getText(i?: number, raw = false): string | string[] | undefined {
if (i === undefined) {
return this.list;
Expand Down
15 changes: 9 additions & 6 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function shouldCapitalize(lastChar: string): boolean {

let spanishSentenceTracker = "";
export async function punctuateWord(
previousWord: string,
previousWord: string | undefined,
currentWord: string,
index: number,
maxindex: number,
Expand All @@ -47,7 +47,8 @@ export async function punctuateWord(

const currentLanguage = Config.language.split("_")[0];

const lastChar = Strings.getLastChar(previousWord);
const lastChar =
previousWord !== undefined ? Strings.getLastChar(previousWord) : undefined;

const funbox = findSingleActiveFunboxWithFunction("punctuateWord");
if (funbox) {
Expand All @@ -56,7 +57,7 @@ export async function punctuateWord(
if (
currentLanguage !== "code" &&
currentLanguage !== "georgian" &&
(index === 0 || shouldCapitalize(lastChar))
(index === 0 || (lastChar !== undefined && shouldCapitalize(lastChar)))
) {
//always capitalise the first word or if there was a dot unless using a code alphabet or the Georgian language

Expand Down Expand Up @@ -371,7 +372,7 @@ function applyFunboxesToWord(

async function applyBritishEnglishToWord(
word: string,
previousWord: string,
previousWord: string | undefined,
): Promise<string> {
if (!Config.britishEnglish) return word;
if (!Config.language.includes("english")) return word;
Expand Down Expand Up @@ -743,7 +744,7 @@ type GetNextWordReturn = {
export async function getNextWord(
wordIndex: number,
wordsBound: number,
previousWord: string,
previousWord: string | undefined,
previousWord2: string | undefined,
): Promise<GetNextWordReturn> {
console.debug("Getting next word", {
Expand Down Expand Up @@ -807,7 +808,9 @@ export async function getNextWord(

const funboxFrequency = getFunboxWordsFrequency() ?? "normal";
let randomWord = currentWordset.randomWord(funboxFrequency);
const previousWordRaw = previousWord.replace(/[.?!":\-,]/g, "").toLowerCase();
const previousWordRaw = previousWord
?.replace(/[.?!":\-,]/g, "")
.toLowerCase();
const previousWord2Raw = previousWord2
?.replace(/[.?!":\-,']/g, "")
.toLowerCase();
Expand Down
Loading