@@ -299,10 +299,10 @@ function main(): void {
299
299
const word = importWordTextBox . value . trim ( ) ;
300
300
if ( word === "" ) {
301
301
showMessage ( NO_WORD_MESSAGE ) ;
302
- } else if ( currentDictionary . isError ( ) ) {
302
+ } else if ( autoParse ( ) && currentDictionary . isError ( ) ) {
303
303
showMessage ( DICTIONARY_ERROR_MESSAGE_ON_IMPORT ) ;
304
304
} else if (
305
- currentDictionary . unwrap ( ) [ 0 ] . has ( word )
305
+ autoParse ( ) && currentDictionary . unwrap ( ) [ 0 ] . has ( word )
306
306
) {
307
307
showMessage ( WORD_ALREADY_IMPORTED_MESSAGE ) ;
308
308
} else {
@@ -316,36 +316,37 @@ function main(): void {
316
316
0 ,
317
317
customDictionaryTextBox . scrollHeight ,
318
318
) ;
319
- updateDictionary ( ) ;
319
+ updateIfCanAutoParse ( ) ;
320
320
} else {
321
321
showMessage ( WORD_NOT_FOUND_MESSAGE ) ;
322
322
}
323
323
}
324
324
}
325
- customDictionaryTextBox . addEventListener ( "input" , ( ) => {
326
- if (
327
- customDictionaryTextBox . value . length <= DICTIONARY_AUTO_PARSE_THRESHOLD
328
- ) {
329
- updateDictionary ( ) ;
330
- }
331
- } ) ;
325
+ customDictionaryTextBox . addEventListener ( "input" , updateIfCanAutoParse ) ;
332
326
discardButton . addEventListener ( "click" , ( ) => {
333
327
customDictionaryTextBox . value = lastSavedText ;
334
328
currentDictionary = lastSavedDictionary ;
335
329
tryCloseDictionary ( ) ;
336
330
} ) ;
337
331
saveButton . addEventListener ( "click" , ( ) => {
338
- if (
339
- customDictionaryTextBox . value . length > DICTIONARY_AUTO_PARSE_THRESHOLD
340
- ) {
332
+ if ( ! autoParse ( ) ) {
341
333
updateDictionary ( ) ;
342
334
}
343
335
tryCloseDictionary ( ) ;
344
336
} ) ;
337
+ function autoParse ( ) : boolean {
338
+ return customDictionaryTextBox . value . length <=
339
+ DICTIONARY_AUTO_PARSE_THRESHOLD ;
340
+ }
345
341
function updateDictionary ( ) : void {
346
342
currentDictionary = dictionaryParser . parse ( customDictionaryTextBox . value ) ;
347
343
showDictionaryError ( ) ;
348
344
}
345
+ function updateIfCanAutoParse ( ) : void {
346
+ if ( autoParse ( ) ) {
347
+ updateDictionary ( ) ;
348
+ }
349
+ }
349
350
function tryCloseDictionary ( ) : void {
350
351
if ( ! currentDictionary . isError ( ) ) {
351
352
lastSavedText = customDictionaryTextBox . value ;
0 commit comments