@@ -42,7 +42,8 @@ non-pu words. Just know that the
42
42
custom dictionary comes with
43
43
limitations. Press Help above to get
44
44
started.` ;
45
- const EMPTY_DEFINITION_PLACEHOLDER = "Definitions here" ;
45
+
46
+ const WORD_NOT_FOUND_MESSAGE = "Word not found" ;
46
47
47
48
const DICTIONARY_LOADING_FAILED_FIXABLE_MESSAGE =
48
49
"Failed to load custom dictionary. This is mostly likely because the " +
@@ -100,11 +101,11 @@ function main(): void {
100
101
const customDictionaryDialogBox = document . getElementById (
101
102
"custom-dictionary-box" ,
102
103
) as HTMLDialogElement ;
103
- const addWordTextBox = document . getElementById (
104
- "add -word" ,
104
+ const importWordTextBox = document . getElementById (
105
+ "import -word" ,
105
106
) as HTMLInputElement ;
106
- const addWordButton = document . getElementById (
107
- "add -word-button" ,
107
+ const importWordButton = document . getElementById (
108
+ "import -word-button" ,
108
109
) as HTMLButtonElement ;
109
110
const customDictionaryTextBox = document . getElementById (
110
111
"custom-dictionary" ,
@@ -240,11 +241,11 @@ function main(): void {
240
241
`${ asComment ( DEFAULT_CUSTOM_DICTIONARY_MESSAGE ) } \n` ;
241
242
}
242
243
} ) ;
243
- addWordButton . addEventListener ( "click" , addWord ) ;
244
- addWordTextBox . addEventListener ( "keydown" , ( event ) => {
244
+ importWordButton . addEventListener ( "click" , importWord ) ;
245
+ importWordTextBox . addEventListener ( "keydown" , ( event ) => {
245
246
if ( event . code === "Enter" && ! event . altKey && ! event . shiftKey ) {
246
247
event . preventDefault ( ) ;
247
- addWord ( ) ;
248
+ importWord ( ) ;
248
249
}
249
250
} ) ;
250
251
function displayToCustomDictionary ( message : string ) : void {
@@ -254,16 +255,15 @@ function main(): void {
254
255
`${ original } ${ append } ${ message . trimEnd ( ) } \n` ;
255
256
customDictionaryTextBox . scrollTo ( 0 , customDictionaryTextBox . scrollHeight ) ;
256
257
}
257
- function addWord ( ) : void {
258
- const word = addWordTextBox . value . trim ( ) ;
258
+ function importWord ( ) : void {
259
+ const word = importWordTextBox . value . trim ( ) ;
259
260
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
+ }
267
267
} else {
268
268
displayToCustomDictionary ( asComment ( INVALID_WORD_ERROR ) ) ;
269
269
}
0 commit comments