From 8d4f4f9b7ae499731b4f6ed2f956a74a9bd79d9f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 9 Feb 2024 15:00:31 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10327 --- app/src/asset/anno.ts | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/app/src/asset/anno.ts b/app/src/asset/anno.ts index 799c56af4..a44c2334b 100644 --- a/app/src/asset/anno.ts +++ b/app/src/asset/anno.ts @@ -309,25 +309,44 @@ const setRelation = (pdf: any) => { `, width: "520px", }); + + const addRelation = () => { + if (/\d{14}-\w{7}/.test(inputElement.value)) { + if (!configItem.ids.includes(inputElement.value)) { + configItem.ids.push(inputElement.value); + updateRelation(pdf, config); + rectElement.dataset.relations = configItem.ids; + dialog.element.querySelector(".b3-list").innerHTML = getRelationHTML(configItem.ids); + } + inputElement.value = ""; + } else { + showMessage("ID " + window.siyuan.languages.invalid); + } + } + + const updateRelation = (pdf: any, config: any) => { + fetchPost("/api/asset/setFileAnnotation", { + path: pdf.appConfig.file.replace(location.origin, "").substr(1) + ".sya", + data: JSON.stringify(config), + }); + } + const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement inputElement.focus(); - + inputElement.addEventListener("keydown", (event) => { + if (event.isComposing) { + return + } + if (event.key === "Enter") { + addRelation(); + } + }) dialog.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.classList.contains("b3-dialog__content")) { const type = target.getAttribute("data-type"); if (type === "add") { - if (/\d{14}-\w{7}/.test(inputElement.value)) { - if (!configItem.ids.includes(inputElement.value)) { - configItem.ids.push(inputElement.value); - updateRelation(pdf, config); - rectElement.dataset.relations = configItem.ids; - dialog.element.querySelector(".b3-list").innerHTML = getRelationHTML(configItem.ids); - } - inputElement.value = ""; - } else { - showMessage("ID " + window.siyuan.languages.invalid); - } + addRelation(); event.preventDefault(); event.stopPropagation(); break; @@ -342,13 +361,6 @@ const setRelation = (pdf: any) => { }); } -const updateRelation = (pdf: any, config: any) => { - fetchPost("/api/asset/setFileAnnotation", { - path: pdf.appConfig.file.replace(location.origin, "").substr(1) + ".sya", - data: JSON.stringify(config), - }); -} - const hideToolbar = (element: HTMLElement) => { element.querySelector(".pdf__util").classList.add("fn__none"); };