diff --git a/app/src/dialog/index.ts b/app/src/dialog/index.ts index 6da12b141..0443378bf 100644 --- a/app/src/dialog/index.ts +++ b/app/src/dialog/index.ts @@ -35,7 +35,7 @@ export class Dialog { this.element.innerHTML = `
- +
${options.title || ""}
${options.content}
@@ -86,30 +86,21 @@ export class Dialog { }); } - public bindInput(inputElement: HTMLInputElement | HTMLTextAreaElement, enterEvent?: () => void) { + public bindInput(inputElement: HTMLInputElement | HTMLTextAreaElement, enterEvent?: () => void, bindEnter = true) { inputElement.focus(); inputElement.addEventListener("keydown", (event: KeyboardEvent) => { if (event.isComposing) { event.preventDefault(); return; } - const confirmElement = document.querySelector("#confirmDialogConfirmBtn"); if (event.key === "Escape") { - if (confirmElement) { - confirmElement.previousElementSibling.previousElementSibling.dispatchEvent(new CustomEvent("click")); - } else { - this.destroy(); - } + this.destroy(); event.preventDefault(); event.stopPropagation(); return; } - if (!event.shiftKey && isNotCtrl(event) && event.key === "Enter" && enterEvent) { - if (confirmElement) { - confirmElement.dispatchEvent(new CustomEvent("click")); - } else { - enterEvent(); - } + if (!event.shiftKey && isNotCtrl(event) && event.key === "Enter" && enterEvent && bindEnter) { + enterEvent(); event.preventDefault(); event.stopPropagation(); } diff --git a/app/src/plugin/Setting.ts b/app/src/plugin/Setting.ts index 18f773ea2..082913f87 100644 --- a/app/src/plugin/Setting.ts +++ b/app/src/plugin/Setting.ts @@ -70,7 +70,7 @@ export class Setting { if (["INPUT", "TEXTAREA"].includes(actionElement.tagName)) { dialog.bindInput(actionElement as HTMLInputElement, () => { btnsElement[1].dispatchEvent(new CustomEvent("click")); - }); + }, actionElement.tagName === "INPUT"); } if (actionElement.tagName === "TEXTAREA") { contentElement.lastElementChild.lastElementChild.insertAdjacentElement("beforeend", actionElement);