Skip to content

Commit c8e9930

Browse files
committed
change "add word" to "import word"
1 parent c0086cf commit c8e9930

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ <h1>
144144
>(Help)</a>
145145
</h1>
146146
<div>
147-
<input id="add-word" type="text" />
148-
<button id="add-word-button">Add word</button>
147+
<input id="import-word" type="text" />
148+
<button id="import-word-button">Import word</button>
149149
</div>
150150
<textarea
151151
id="custom-dictionary"

src/main.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ non-pu words. Just know that the
4242
custom dictionary comes with
4343
limitations. Press Help above to get
4444
started.`;
45-
const EMPTY_DEFINITION_PLACEHOLDER = "Definitions here";
45+
46+
const WORD_NOT_FOUND_MESSAGE = "Word not found";
4647

4748
const 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-zA-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

Comments
 (0)