From 6be2faa9c2672faa475e87e1b0a60b60f33a60a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Tue, 29 Sep 2020 11:23:57 +0300 Subject: [PATCH] Fix note citation insertion breaking when citing the same item in a note --- chrome/content/zotero/xpcom/integration.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 8c3a905d44..a77909a3e3 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1435,8 +1435,11 @@ Zotero.Integration.Session.prototype._processNote = function (item) { placeholderIDs.push(placeholderID); let placeholderURL = NOTE_CITATION_PLACEHOLDER_LINK + placeholderID; // Split out the citation element and replace with a placeholder link - text = text.split(citationElem.outerHTML) - .join(`${citationElem.textContent}`); + let startIndex = text.indexOf(citationElem.outerHTML); + let endIndex = startIndex + citationElem.outerHTML.length; + text = text.slice(0, startIndex) + + `${citationElem.textContent}` + + text.slice(endIndex); } catch (e) { e.message = `Failed to parse a citation from a note: ${decodeURIComponent(citationElem.dataset.citation)}`;