瀏覽代碼

:art: 插件中不绑定 TEXTAREA 回车事件

Vanessa 1 年之前
父節點
當前提交
8f639fb07f
共有 2 個文件被更改,包括 6 次插入15 次删除
  1. 5 14
      app/src/dialog/index.ts
  2. 1 1
      app/src/plugin/Setting.ts

+ 5 - 14
app/src/dialog/index.ts

@@ -35,7 +35,7 @@ export class Dialog {
         this.element.innerHTML = `<div class="b3-dialog" style="z-index: ${++window.siyuan.zIndex};">
 <div class="b3-dialog__scrim"${options.transparent ? 'style="background-color:transparent"' : ""}></div>
 <div class="b3-dialog__container" style="width:${options.width || "auto"};height:${options.height || "auto"}">
-  <svg ${(isMobile() && options.title) ? 'style="top:0;right:0;"' : ""} class="b3-dialog__close${(this.disableClose||options.hideCloseIcon) ? " fn__none" : ""}"><use xlink:href="#iconCloseRound"></use></svg>
+  <svg ${(isMobile() && options.title) ? 'style="top:0;right:0;"' : ""} class="b3-dialog__close${(this.disableClose || options.hideCloseIcon) ? " fn__none" : ""}"><use xlink:href="#iconCloseRound"></use></svg>
   <div class="resize__move b3-dialog__header${options.title ? "" : " fn__none"}" onselectstart="return false;">${options.title || ""}</div>
   <div class="b3-dialog__body">${options.content}</div>
   <div class="resize__rd"></div><div class="resize__ld"></div><div class="resize__lt"></div><div class="resize__rt"></div><div class="resize__r"></div><div class="resize__d"></div><div class="resize__t"></div><div class="resize__l"></div>
@@ -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();
             }

+ 1 - 1
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);