From 8c7b7e9706002e8f5bc3c13359865f4b1ebd808f Mon Sep 17 00:00:00 2001 From: xiangyu <3170102889@zju.edu.cn> Date: Sun, 8 May 2022 18:12:29 +0800 Subject: [PATCH] fix: add annotation link bug --- src/events.ts | 25 +++++++++++++++---------- src/views.ts | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/events.ts b/src/events.ts index 8f0a6c4..2b1348c 100644 --- a/src/events.ts +++ b/src/events.ts @@ -632,18 +632,21 @@ class AddonEvents extends AddonBase { const annotations = message.content.params.annotations; const annotationItem: ZoteroItem = message.content.params.annotationItem; - const text = annotationItem.annotationComment; - let link = text.substring(text.search(/zotero:\/\/note\//g)); - link = link.substring(0, link.search('"')); + if (annotationItem.annotationComment) { + const text = annotationItem.annotationComment; + let link = text.substring(text.search(/zotero:\/\/note\//g)); + link = link.substring(0, link.search('"')); - if (link) { - const note = (await this._Addon.knowledge.getNoteFromLink(link)).item; - if (note && note.id) { - Zotero.debug(note); - ZoteroPane.openNoteWindow(note.id); - return; + if (link) { + const note = (await this._Addon.knowledge.getNoteFromLink(link)).item; + if (note && note.id) { + Zotero.debug(note); + ZoteroPane.openNoteWindow(note.id); + return; + } } } + const note: ZoteroItem = new Zotero.Item("note"); note.parentID = Zotero.Items.get( annotations[0].attachmentItemID @@ -663,7 +666,9 @@ class AddonEvents extends AddonBase { groupID = `${library.id}`; } let noteKey = note.key; - annotationItem.annotationComment = `${annotationItem.annotationComment}\nnote link: "zotero://note/${groupID}/${noteKey}/"`; + annotationItem.annotationComment = `${ + annotationItem.annotationComment ? annotationItem.annotationComment : "" + }\nnote link: "zotero://note/${groupID}/${noteKey}/"`; await annotationItem.saveTx(); ZoteroPane.openNoteWindow(note.id); let t = 0; diff --git a/src/views.ts b/src/views.ts index 1064d36..ba45f06 100644 --- a/src/views.ts +++ b/src/views.ts @@ -115,7 +115,6 @@ class AddonViews extends AddonBase { } const popup = _document.createElement("div"); popup.setAttribute("class", "popup"); - popup.setAttribute("style", "right: -100px;"); popup.setAttribute("id", id); for (let buttonParam of buttons) { const button = _document.createElement("button"); @@ -142,6 +141,8 @@ class AddonViews extends AddonBase { }); } parentDropDown.append(popup); + Zotero.debug(popup.offsetWidth); + popup.setAttribute("style", `right: -${popup.offsetWidth / 2 - 15}px;`); return popup; }