@@ -42,14 +42,14 @@ non-pu words. Just know that the
4242custom dictionary comes with
4343limitations. Press Help above to get
4444started.` ;
45- const EMPTY_DEFINITION_PLACEHOLDER = "Definitions here" ;
4645
4746const DICTIONARY_LOADING_FAILED_FIXABLE_MESSAGE =
4847 "Failed to load custom dictionary. This is mostly likely because the " +
4948 "syntax has been updated and your custom dictionary still uses the old " +
5049 "syntax. Please fix it. Apologies for the inconvenience." ;
5150const DICTIONARY_LOADING_FAILED_UNFIXABLE_MESSAGE =
5251 "Failed to load custom dictionary. Please report this." ;
52+ const WORD_NOT_FOUND_MESSAGE = "Error: Word not found." ;
5353const INVALID_WORD_ERROR =
5454 "Error: Invalid word to add (You may remove this line)." ;
5555const DICTIONARY_ERROR_FIXABLE_MESSAGE =
@@ -100,11 +100,11 @@ function main(): void {
100100 const customDictionaryDialogBox = document . getElementById (
101101 "custom-dictionary-box" ,
102102 ) as HTMLDialogElement ;
103- const addWordTextBox = document . getElementById (
104- "add -word" ,
103+ const importWordTextBox = document . getElementById (
104+ "import -word" ,
105105 ) as HTMLInputElement ;
106- const addWordButton = document . getElementById (
107- "add -word-button" ,
106+ const importWordButton = document . getElementById (
107+ "import -word-button" ,
108108 ) as HTMLButtonElement ;
109109 const customDictionaryTextBox = document . getElementById (
110110 "custom-dictionary" ,
@@ -240,11 +240,11 @@ function main(): void {
240240 `${ asComment ( DEFAULT_CUSTOM_DICTIONARY_MESSAGE ) } \n` ;
241241 }
242242 } ) ;
243- addWordButton . addEventListener ( "click" , addWord ) ;
244- addWordTextBox . addEventListener ( "keydown" , ( event ) => {
243+ importWordButton . addEventListener ( "click" , importWord ) ;
244+ importWordTextBox . addEventListener ( "keydown" , ( event ) => {
245245 if ( event . code === "Enter" && ! event . altKey && ! event . shiftKey ) {
246246 event . preventDefault ( ) ;
247- addWord ( ) ;
247+ importWord ( ) ;
248248 }
249249 } ) ;
250250 function displayToCustomDictionary ( message : string ) : void {
@@ -254,16 +254,15 @@ function main(): void {
254254 `${ original } ${ append } ${ message . trimEnd ( ) } \n` ;
255255 customDictionaryTextBox . scrollTo ( 0 , customDictionaryTextBox . scrollHeight ) ;
256256 }
257- function addWord ( ) : void {
258- const word = addWordTextBox . value . trim ( ) ;
257+ function importWord ( ) : void {
258+ const word = importWordTextBox . value . trim ( ) ;
259259 if ( / ^ [ a - z ] [ a - z A - Z ] * $ / . test ( word ) ) {
260- const dictionaryEntry = dictionary . get ( word ) ;
261- const definitions = dictionaryEntry ?. src ??
262- `\n${
263- asComment ( EMPTY_DEFINITION_PLACEHOLDER )
264- . replaceAll ( / ^ / gm, " " )
265- } `;
266- displayToCustomDictionary ( `${ word } :${ definitions } ` ) ;
260+ const definitions = dictionary . get ( word ) ?. src ;
261+ if ( definitions != null ) {
262+ displayToCustomDictionary ( `${ word } :${ definitions } ` ) ;
263+ } else {
264+ displayToCustomDictionary ( asComment ( WORD_NOT_FOUND_MESSAGE ) ) ;
265+ }
267266 } else {
268267 displayToCustomDictionary ( asComment ( INVALID_WORD_ERROR ) ) ;
269268 }
0 commit comments