mirror of
				https://github.com/monkeytypegame/monkeytype.git
				synced 2025-10-31 03:08:29 +08:00 
			
		
		
		
	fixed a bug where custom random text would not be the correct length with show all lines disabled
This commit is contained in:
		
							parent
							
								
									e9f6bfc91c
								
							
						
					
					
						commit
						31a548010e
					
				
					 1 changed files with 24 additions and 7 deletions
				
			
		|  | @ -599,19 +599,32 @@ function addWord() { | |||
|   if ( | ||||
|     !config.showAllLines && | ||||
|     (wordsList.length - inputHistory.length > 60 || | ||||
|       (config.mode === "words" && wordsList.length >= config.words)) | ||||
|       (config.mode === "words" && wordsList.length >= config.words) || | ||||
|       (config.mode === "custom" && wordsList.length >= customTextWordCount)) | ||||
|   ) | ||||
|     return; | ||||
|   let language = words[config.language]; | ||||
|   if (config.mode == "custom") { | ||||
|     language = customText; | ||||
|   } | ||||
|   let randomWord = language[Math.floor(Math.random() * language.length)]; | ||||
|   previousWord = wordsList[wordsList.length - 1]; | ||||
|   previousWordStripped = previousWord.replace(/[.?!":\-,]/g, "").toLowerCase(); | ||||
|   while ( | ||||
|     previousWordStripped == randomWord || | ||||
|     randomWord.indexOf(" ") > -1 || | ||||
|     (!config.punctuation && randomWord == "I") | ||||
|   ) { | ||||
|   previousWord2Stripped = wordsList[wordsList.length - 2] | ||||
|     .replace(/[.?!":\-,]/g, "") | ||||
|     .toLowerCase(); | ||||
| 
 | ||||
|   if (config.mode == "custom" && language.length < 3) { | ||||
|     randomWord = language[Math.floor(Math.random() * language.length)]; | ||||
|   } else { | ||||
|     while ( | ||||
|       previousWordStripped == randomWord || | ||||
|       previousWord2Stripped == randomWord || | ||||
|       randomWord.indexOf(" ") > -1 || | ||||
|       (!config.punctuation && randomWord == "I") | ||||
|     ) { | ||||
|       randomWord = language[Math.floor(Math.random() * language.length)]; | ||||
|     } | ||||
|   } | ||||
|   if (config.punctuation && config.mode != "custom") { | ||||
|     randomWord = punctuateWord(previousWord, randomWord, wordsList.length, 0); | ||||
|  | @ -3392,7 +3405,11 @@ $(document).keydown((event) => { | |||
|           addWord(); | ||||
|         } | ||||
|       } else { | ||||
|         if (config.mode == "time" || config.mode == "words") { | ||||
|         if ( | ||||
|           config.mode == "time" || | ||||
|           config.mode == "words" || | ||||
|           (config.mode == "custom" && customTextIsRandom) | ||||
|         ) { | ||||
|           addWord(); | ||||
|         } | ||||
|       } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue