commit 9c7271c60659a44ef8ded83fc1e8eb46d5659300
parent 9ae582e34558fc43507c55de9490a54b3e82bb9a
Author: Adomas VenĨkauskas <adomas.ven@gmail.com>
Date: Wed, 28 Mar 2018 14:40:18 +0300
Fix citations copied from other documents causing citeproc errors
Might slow down the initial interaction with a document in
automatic updates mode.
Diffstat:
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js
@@ -398,7 +398,6 @@ Zotero.Integration = new function() {
}
if (!session) {
session = new Zotero.Integration.Session(doc, app);
- session.reload = true;
}
try {
yield session.setData(data);
@@ -1312,6 +1311,7 @@ Zotero.Integration.Session = function(doc, app) {
this.embeddedItems = {};
this.embeddedZoteroItems = {};
this.embeddedItemsByURI = {};
+ this.citationsByIndex = {};
this.resetRequest(doc);
this.primaryFieldType = app.primaryFieldType;
this.secondaryFieldType = app.secondaryFieldType;
@@ -1328,9 +1328,22 @@ Zotero.Integration.Session.prototype.resetRequest = function(doc) {
this.bibliographyHasChanged = false;
this.bibliographyDataHasChanged = false;
- this.updateIndices = {};
+ // After adding fields to the session
+ // citations that are new to the document will be marked
+ // as new, so that they are correctly loaded into and processed with citeproc
this.newIndices = {};
-
+ // After the processing of new indices with citeproc, some
+ // citations require additional work (because of disambiguation, numbering changes, etc)
+ // and will be marked for an additional reprocessing with citeproc to retrieve updated text
+ this.updateIndices = {};
+
+ // When processing citations this list will be checked for citations that are new to the document
+ // (i.e. copied from somewhere else) and marked as newIndices to be processed with citeproc if
+ // not present
+ this.oldCitations = new Set();
+ for (let i in this.citationsByIndex) {
+ this.oldCitations.add(this.citationsByIndex[i].citationID);
+ }
this.citationsByItemID = {};
this.citationsByIndex = {};
this.documentCitationIDs = {};
@@ -1561,6 +1574,11 @@ Zotero.Integration.Session.prototype.addCitation = Zotero.Promise.coroutine(func
}
this.newIndices[index] = true;
}
+ // Deal with citations that are copied into the document from somewhere else
+ // and have not been added to the processor yet
+ if (! this.oldCitations.has(citation.citationID)) {
+ this.newIndices[index] = true;
+ }
Zotero.debug("Integration: Adding citationID "+citation.citationID);
this.documentCitationIDs[citation.citationID] = index;
});