fix excessive processCitationCluster calls

This commit is contained in:
Simon Kornblith 2010-06-03 22:30:32 +00:00
parent 0726ace6e9
commit e44dcb1bb4

View file

@ -1331,24 +1331,25 @@ Zotero.Integration.Session.prototype.formatCitation = function(index, citation)
* Updates the list of citations to be serialized to the document * Updates the list of citations to be serialized to the document
*/ */
Zotero.Integration.Session.prototype.updateCitations = function(force) { Zotero.Integration.Session.prototype.updateCitations = function(force) {
var allUpdatesForced = false;
var forcedUpdates = {}; var forcedUpdates = {};
if(force) { if(force) {
allUpdatesForced = true;
// make sure at least one citation gets updated // make sure at least one citation gets updated
var haveUpdates = false;
updateLoop: for each(var indexList in [this.newIndices, this.updateIndices]) { updateLoop: for each(var indexList in [this.newIndices, this.updateIndices]) {
for(var i in indexList) { for(var i in indexList) {
if(!this.citationsByIndex[i].properties.delete) { if(!this.citationsByIndex[i].properties.delete) {
haveUpdates = true; allUpdatesForced = false;
break updateLoop; break updateLoop;
} }
} }
} }
if(!haveUpdates) { if(allUpdatesForced) {
for(i in this.citationsByIndex) { for(i in this.citationsByIndex) {
if(this.citationsByIndex[i] && !this.citationsByIndex[i].properties.delete) { if(this.citationsByIndex[i] && !this.citationsByIndex[i].properties.delete) {
forcedUpdates[i] = true; forcedUpdates[i] = true;
break;
} }
} }
} }
@ -1358,7 +1359,8 @@ Zotero.Integration.Session.prototype.updateCitations = function(force) {
Zotero.debug([key for(key in this.newIndices)]); Zotero.debug([key for(key in this.newIndices)]);
Zotero.debug("Zotero.Integration: indices of updated citations"); Zotero.debug("Zotero.Integration: indices of updated citations");
Zotero.debug([key for(key in this.updateIndices)]); Zotero.debug([key for(key in this.updateIndices)]);
Zotero.debug("Zotero.Integration: indices of forcedUpdates");
Zotero.debug([key for(key in forcedUpdates)]);
var deleteCitations = []; var deleteCitations = [];
for each(var indexList in [this.newIndices, this.updateIndices, forcedUpdates]) { for each(var indexList in [this.newIndices, this.updateIndices, forcedUpdates]) {
@ -1380,6 +1382,11 @@ Zotero.Integration.Session.prototype.updateCitations = function(force) {
} }
} }
if(allUpdatesForced) {
this.newIndices = {};
this.updateIndices = {};
}
return deleteCitations; return deleteCitations;
} }
@ -1492,9 +1499,9 @@ Zotero.Integration.Session.prototype.previewCitation = function(citation) {
throw e; throw e;
} }
var citationText = this.citationText[citation.properties.index]; // we don't delete the citationText only because the add citation dialog always calls
delete this.citationText[citation.properties.index]; // previewCitation before returning
return citationText; return this.citationText[citation.properties.index];
} }
/** /**