@@ -254,7 +254,7 @@ class AddonEvents extends AddonBase {
254254
255255 message . content . editorInstance . _knowledgeUIInitialized = false ;
256256
257- const noteItem = Zotero . Items . get (
257+ const noteItem : ZoteroItem = Zotero . Items . get (
258258 message . content . editorInstance . _item . id
259259 ) ;
260260 if ( ! noteItem . isNote ( ) ) {
@@ -269,15 +269,15 @@ class AddonEvents extends AddonBase {
269269 message . content . editorInstance ,
270270 "knowledge-start" ,
271271 isMainKnowledge ? "isMainKnowledge" : "notMainKnowledge" ,
272- isMainKnowledge ? "Edit the main Note in Workspace" : "Open Workspace" ,
272+ isMainKnowledge ? "Edit the Main Note in Workspace" : "Open Workspace" ,
273273 "openWorkspace" ,
274274 "start"
275275 ) ;
276276 const addLinkDropDown : Element = await this . _Addon . views . addEditorButton (
277277 message . content . editorInstance ,
278278 "knowledge-addlink" ,
279279 "addToKnowledge" ,
280- "Add link of current note to the main note " ,
280+ "Add Link of Current Note to Main Note " ,
281281 "addToKnowledge" ,
282282 "middle"
283283 ) ;
@@ -309,6 +309,35 @@ class AddonEvents extends AddonBase {
309309 popup . remove ( ) ;
310310 } ) ;
311311 } ) ;
312+ let topItem = noteItem . parentItem ;
313+ while ( topItem && ! topItem . isRegularItem ( ) ) {
314+ topItem = topItem . parentItem ;
315+ }
316+ if ( topItem ) {
317+ const addCitationButton : Element =
318+ await this . _Addon . views . addEditorButton (
319+ message . content . editorInstance ,
320+ "knowledge-addcitation" ,
321+ "addCitation" ,
322+ "Insert Note's Parent Citation" ,
323+ "addCitation" ,
324+ "middle"
325+ ) ;
326+ addCitationButton . addEventListener ( "click" , async ( e ) => {
327+ let format = Zotero . QuickCopy . getFormatFromURL (
328+ Zotero . QuickCopy . lastActiveURL
329+ ) ;
330+ format = Zotero . QuickCopy . unserializeSetting ( format ) ;
331+ const cite = Zotero . QuickCopy . getContentFromItems (
332+ [ topItem ] ,
333+ format ,
334+ null ,
335+ 0
336+ ) ;
337+ this . _Addon . knowledge . addLineToNote ( noteItem , cite . html , 65535 ) ;
338+ } ) ;
339+ }
340+
312341 await this . _Addon . views . addEditorButton (
313342 message . content . editorInstance ,
314343 "knowledge-end" ,
@@ -594,7 +623,7 @@ class AddonEvents extends AddonBase {
594623 if ( text . trim ( ) ) {
595624 if ( this . _Addon . knowledge . currentNodeID < 0 ) {
596625 // Add a new H1
597- this . _Addon . knowledge . addSubLineToNote (
626+ this . _Addon . knowledge . addLineToNote (
598627 undefined ,
599628 `<h1>${ text } </h1>` ,
600629 - 1
@@ -605,7 +634,7 @@ class AddonEvents extends AddonBase {
605634 undefined ,
606635 this . _Addon . knowledge . currentNodeID
607636 ) ;
608- this . _Addon . knowledge . addSubLineToNote (
637+ this . _Addon . knowledge . addLineToNote (
609638 undefined ,
610639 `<h${ node . model . rank } >${ text } </h${ node . model . rank } >` ,
611640 node . model . endIndex
@@ -809,8 +838,14 @@ class AddonEvents extends AddonBase {
809838 if ( link ) {
810839 const note = ( await this . _Addon . knowledge . getNoteFromLink ( link ) ) . item ;
811840 if ( note && note . id ) {
812- Zotero . debug ( note ) ;
813- ZoteroPane . openNoteWindow ( note . id ) ;
841+ await this . onEditorEvent (
842+ new EditorMessage ( "onNoteLink" , {
843+ params : {
844+ item : note ,
845+ infoText : "OK" ,
846+ } ,
847+ } )
848+ ) ;
814849 return ;
815850 }
816851 }
@@ -830,18 +865,10 @@ class AddonEvents extends AddonBase {
830865 note . addTag ( tag . tag , tag . type ) ;
831866 }
832867 await note . saveTx ( ) ;
833- let libraryID = note . libraryID ;
834- let library = Zotero . Libraries . get ( libraryID ) ;
835- let groupID : string ;
836- if ( library . libraryType === "user" ) {
837- groupID = "u" ;
838- } else if ( library . libraryType === "group" ) {
839- groupID = `${ library . id } ` ;
840- }
841- let noteKey = note . key ;
868+
842869 annotationItem . annotationComment = `${
843870 annotationItem . annotationComment ? annotationItem . annotationComment : ""
844- } \nnote link: "zotero://note/ ${ groupID } / ${ noteKey } / "`;
871+ } \nnote link: "${ this . _Addon . knowledge . getNoteLink ( note ) } "`;
845872 await annotationItem . saveTx ( ) ;
846873 ZoteroPane . openNoteWindow ( note . id ) ;
847874 let t = 0 ;
0 commit comments