Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/10327

Vanessa8d4f4f9b7ae4
diff --git a/app/src/asset/anno.ts b/app/src/asset/anno.ts
index 799c56af44..a44c2334b7 100644
--- a/app/src/asset/anno.ts
+++ b/app/src/asset/anno.ts
@@ -309,25 +309,44 @@ const setRelation = (pdf: any) => {
</div>`,
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");
};