Remove field codes for empty bibliographies when refreshing
This happens when a user inserts a bibliography in the middle of a paragraph and doesn't fully delete it. Also remove unused code for deleting citations from the document.
This commit is contained in:
parent
2a9d1d2693
commit
263eb508cc
1 changed files with 11 additions and 32 deletions
|
@ -1234,6 +1234,7 @@ Zotero.Integration.Document.prototype.setDocPrefs = function() {
|
|||
|
||||
// Refresh contents
|
||||
fieldGetter = new Zotero.Integration.Fields(me._session, me._doc);
|
||||
fieldGetter.ignoreEmptyBibliography = false;
|
||||
return fieldGetter.updateSession().fail(Zotero.Integration.onFieldError)
|
||||
.then(fieldGetter.updateDocument.bind(
|
||||
fieldGetter, FORCE_CITATIONS_RESET_TEXT, true, true));
|
||||
|
@ -1260,6 +1261,7 @@ Zotero.Integration.Document.JSEnumerator.prototype.getNext = function() {
|
|||
Zotero.Integration.Fields = function(session, doc) {
|
||||
this._session = session;
|
||||
this._doc = doc;
|
||||
this.ignoreEmptyBibliography = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1489,10 +1491,14 @@ Zotero.Integration.Fields.prototype._processFields = function(i) {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
} else if(type === INTEGRATION_TYPE_BIBLIOGRAPHY && field.getText().trim() !== "") {
|
||||
this._bibliographyFields.push(field);
|
||||
if(!this._session.bibliographyData && !this._bibliographyData) {
|
||||
this._bibliographyData = content;
|
||||
} else if(type === INTEGRATION_TYPE_BIBLIOGRAPHY) {
|
||||
if(this.ignoreEmptyBibliography && field.getText().trim() === "") {
|
||||
this._removeCodeFields[i] = true;
|
||||
} else {
|
||||
this._bibliographyFields.push(field);
|
||||
if(!this._session.bibliographyData && !this._bibliographyData) {
|
||||
this._bibliographyData = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2487,33 +2493,6 @@ Zotero.Integration.Session.prototype.unserializeCitation = function(arg, index)
|
|||
return citation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a citation for removal
|
||||
*/
|
||||
Zotero.Integration.Session.prototype.deleteCitation = function(index) {
|
||||
var oldCitation = (this.citationsByIndex[index] ? this.citationsByIndex[index] : false);
|
||||
this.citationsByIndex[index] = {properties:{"delete":true}};
|
||||
|
||||
if(oldCitation && oldCitation.citationItems & oldCitation.properties.added) {
|
||||
// clear out old citations if necessary
|
||||
for each(var citationItem in oldCitation.citationItems) {
|
||||
if(this.citationsByItemID[citationItem.id]) {
|
||||
var indexInItemID = this.citationsByItemID[citationItem.id].indexOf(oldCitation);
|
||||
if(indexInItemID !== -1) {
|
||||
this.citationsByItemID[citationItem.id] = this.citationsByItemID[citationItem.id].splice(indexInItemID, 1);
|
||||
if(this.citationsByItemID[citationItem.id].length == 0) {
|
||||
delete this.citationsByItemID[citationItem.id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Zotero.debug("Integration: Deleting old citationID "+oldCitation.citationID);
|
||||
if(oldCitation.citationID) delete this.citeprocCitationIDs[oldCitation.citationID];
|
||||
|
||||
this.updateIndices[index] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets integration bibliography
|
||||
*/
|
||||
|
@ -2654,7 +2633,7 @@ Zotero.Integration.Session.prototype._updateCitations = function() {
|
|||
index = parseInt(index);
|
||||
|
||||
var citation = this.citationsByIndex[index];
|
||||
if(!citation) continue;
|
||||
if(!citation || citation.properties.delete) continue;
|
||||
if(this.formatCitation(index, citation)) {
|
||||
this.bibliographyHasChanged = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue