Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Vanessa8f639fb07f5d
diff --git a/app/src/dialog/index.ts b/app/src/dialog/index.ts
index 6da12b141c..0443378bf7 100644
--- a/app/src/dialog/index.ts
+++ b/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();
}
diff --git a/app/src/plugin/Setting.ts b/app/src/plugin/Setting.ts
index 18f773ea29..082913f874 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);