Fix citations copied from other documents causing citeproc errors

Might slow down the initial interaction with a document in
automatic updates mode.
This commit is contained in:
Adomas Venčkauskas 2018-03-28 14:40:18 +03:00
parent 9ae582e345
commit 9c7271c606

View file

@ -398,7 +398,6 @@ Zotero.Integration = new function() {
} }
if (!session) { if (!session) {
session = new Zotero.Integration.Session(doc, app); session = new Zotero.Integration.Session(doc, app);
session.reload = true;
} }
try { try {
yield session.setData(data); yield session.setData(data);
@ -1312,6 +1311,7 @@ Zotero.Integration.Session = function(doc, app) {
this.embeddedItems = {}; this.embeddedItems = {};
this.embeddedZoteroItems = {}; this.embeddedZoteroItems = {};
this.embeddedItemsByURI = {}; this.embeddedItemsByURI = {};
this.citationsByIndex = {};
this.resetRequest(doc); this.resetRequest(doc);
this.primaryFieldType = app.primaryFieldType; this.primaryFieldType = app.primaryFieldType;
this.secondaryFieldType = app.secondaryFieldType; this.secondaryFieldType = app.secondaryFieldType;
@ -1328,9 +1328,22 @@ Zotero.Integration.Session.prototype.resetRequest = function(doc) {
this.bibliographyHasChanged = false; this.bibliographyHasChanged = false;
this.bibliographyDataHasChanged = 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 = {}; 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.citationsByItemID = {};
this.citationsByIndex = {}; this.citationsByIndex = {};
this.documentCitationIDs = {}; this.documentCitationIDs = {};
@ -1561,6 +1574,11 @@ Zotero.Integration.Session.prototype.addCitation = Zotero.Promise.coroutine(func
} }
this.newIndices[index] = true; 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); Zotero.debug("Integration: Adding citationID "+citation.citationID);
this.documentCitationIDs[citation.citationID] = index; this.documentCitationIDs[citation.citationID] = index;
}); });