@@ -24,6 +24,7 @@ import {
24
24
resetDomToDefault ,
25
25
} from "./settings_frontend.ts" ;
26
26
import { translate } from "./translator/translator.ts" ;
27
+ import { closestString } from "@std/text/closest-string" ;
27
28
28
29
const DICTIONARY_AUTO_PARSE_THRESHOLD = 5000 ;
29
30
const INITIAL_PAGE_SIZE = 100 ;
@@ -61,8 +62,10 @@ const DICTIONARY_LOADING_FAILED_MESSAGE =
61
62
"syntax has been updated and your custom dictionary still uses the old " +
62
63
"syntax. Please fix it. Apologies for the inconvenience." ;
63
64
const NO_WORD_MESSAGE = "Please provide a word" ;
64
- const WORD_NOT_FOUND_MESSAGE = "Word not found" ;
65
- const WORD_ALREADY_IMPORTED_MESSAGE = "The word is already imported" ;
65
+ const WORD_NOT_FOUND_MESSAGE = ( word : string , suggestion : string ) =>
66
+ `"${ word } " doesn't exist in the dictionary. Maybe you mean "${ suggestion } ".` ;
67
+ const WORD_ALREADY_IMPORTED_MESSAGE = ( word : string ) =>
68
+ `"${ word } " is already imported` ;
66
69
const DICTIONARY_ERROR_MESSAGE = "Please fix the errors before saving" ;
67
70
68
71
function main ( ) {
@@ -337,13 +340,11 @@ function main() {
337
340
} ) ;
338
341
function importWord ( ) {
339
342
const word = importWordTextBox . value . trim ( ) ;
340
- if ( word === "" ) {
341
- showMessage ( NO_WORD_MESSAGE ) ;
342
- } else if (
343
+ if (
343
344
autoParse ( ) && ! currentDictionary . isError ( ) &&
344
345
currentDictionary . unwrap ( ) [ 0 ] . has ( word )
345
346
) {
346
- showMessage ( WORD_ALREADY_IMPORTED_MESSAGE ) ;
347
+ showMessage ( WORD_ALREADY_IMPORTED_MESSAGE ( word ) ) ;
347
348
} else {
348
349
const definitions = dictionary . get ( word ) ?. source ;
349
350
if ( definitions != null ) {
@@ -356,8 +357,19 @@ function main() {
356
357
customDictionaryTextBox . scrollHeight ,
357
358
) ;
358
359
updateIfCanAutoParse ( ) ;
360
+ } else if ( word === "" ) {
361
+ showMessage ( NO_WORD_MESSAGE ) ;
359
362
} else {
360
- showMessage ( WORD_NOT_FOUND_MESSAGE ) ;
363
+ showMessage (
364
+ WORD_NOT_FOUND_MESSAGE (
365
+ word ,
366
+ closestString (
367
+ word ,
368
+ [ ...dictionary . keys ( ) ] ,
369
+ { caseSensitive : true } ,
370
+ ) ,
371
+ ) ,
372
+ ) ;
361
373
}
362
374
}
363
375
}
0 commit comments