@@ -42,7 +42,8 @@ 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" ;
45+
46+ const WORD_NOT_FOUND_MESSAGE = "Word not found" ;
4647
4748const DICTIONARY_LOADING_FAILED_FIXABLE_MESSAGE =
4849 "Failed to load custom dictionary. This is mostly likely because the " +
@@ -100,11 +101,11 @@ function main(): void {
100101 const customDictionaryDialogBox = document . getElementById (
101102 "custom-dictionary-box" ,
102103 ) as HTMLDialogElement ;
103- const addWordTextBox = document . getElementById (
104- "add -word" ,
104+ const importWordTextBox = document . getElementById (
105+ "import -word" ,
105106 ) as HTMLInputElement ;
106- const addWordButton = document . getElementById (
107- "add -word-button" ,
107+ const importWordButton = document . getElementById (
108+ "import -word-button" ,
108109 ) as HTMLButtonElement ;
109110 const customDictionaryTextBox = document . getElementById (
110111 "custom-dictionary" ,
@@ -240,11 +241,11 @@ function main(): void {
240241 `${ asComment ( DEFAULT_CUSTOM_DICTIONARY_MESSAGE ) } \n` ;
241242 }
242243 } ) ;
243- addWordButton . addEventListener ( "click" , addWord ) ;
244- addWordTextBox . addEventListener ( "keydown" , ( event ) => {
244+ importWordButton . addEventListener ( "click" , importWord ) ;
245+ importWordTextBox . addEventListener ( "keydown" , ( event ) => {
245246 if ( event . code === "Enter" && ! event . altKey && ! event . shiftKey ) {
246247 event . preventDefault ( ) ;
247- addWord ( ) ;
248+ importWord ( ) ;
248249 }
249250 } ) ;
250251 function displayToCustomDictionary ( message : string ) : void {
@@ -254,16 +255,15 @@ function main(): void {
254255 `${ original } ${ append } ${ message . trimEnd ( ) } \n` ;
255256 customDictionaryTextBox . scrollTo ( 0 , customDictionaryTextBox . scrollHeight ) ;
256257 }
257- function addWord ( ) : void {
258- const word = addWordTextBox . value . trim ( ) ;
258+ function importWord ( ) : void {
259+ const word = importWordTextBox . value . trim ( ) ;
259260 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 } ` ) ;
261+ const definitions = dictionary . get ( word ) ?. src ;
262+ if ( definitions != null ) {
263+ displayToCustomDictionary ( `${ word } :${ definitions } ` ) ;
264+ } else {
265+ displayToCustomDictionary ( asComment ( WORD_NOT_FOUND_MESSAGE ) ) ;
266+ }
267267 } else {
268268 displayToCustomDictionary ( asComment ( INVALID_WORD_ERROR ) ) ;
269269 }
0 commit comments