Remove bibliography when last citation is deleted. Closes #3474

This commit is contained in:
Adomas Venčkauskas 2026-08-25 15:54:37 +03:00
parent 753dbf557a
commit baa47e3bb9
2 changed files with 29 additions and 8 deletions

View file

@ -1333,13 +1333,19 @@ Zotero.Integration.Session.prototype._updateDocument = async function (forceCita
var indicesToUpdate = Object.keys(this.processIndices);
// Add bibliography indices to the above indices
if (this.bibliography // if bibliography exists
&& Object.keys(this.citationsByIndex).length // and doc has citations
&& (this.bibliographyHasChanged // and bibliography changed
|| forceBibliography)) { // or if we should generate regardless of
// changes
for (let field of this._bibliographyFields) {
indicesToUpdate.push(field.index);
if (this.bibliography) { // if bibliography exists
if (!Object.keys(this.citationsByIndex).length) { // and there are no citations
for (let field of this._bibliographyFields) {
// Remove all bibliography fields
this._deleteFields[field.index] = true;
}
}
else if (this.bibliographyHasChanged // if bibliography changed
|| forceBibliography) { // or force flag is active
for (let field of this._bibliographyFields) {
// Update all bibliography fields
indicesToUpdate.push(field.index);
}
}
}
@ -1496,7 +1502,7 @@ Zotero.Integration.Session.prototype._updateDocument = async function (forceCita
var deleteFields = Object.keys(this._deleteFields).sort((a, b) => b - a);
for (let fieldIndex of deleteFields) {
this._fields[fieldIndex].delete();
await this._fields[fieldIndex].delete();
}
this.processIndices = {}
}

View file

@ -1088,6 +1088,21 @@ describe("Zotero.Integration", function () {
});
describe('#refresh', function () {
it('should delete the bibliography when the last citation is removed', async function () {
var docID = this.test.fullTitle();
setAddEditItems(testItems[0]);
await initDoc(docID);
await execCommand('addEditCitation', docID);
await execCommand('addEditBibliography', docID);
var doc = applications[docID].doc;
assert.equal(doc.fields.length, 2);
await doc.fields[0].delete();
await execCommand('refresh', docID);
assert.equal(doc.fields.length, 0);
});
it ('should properly disambiguate author after editing in the database', async function () {
var docID = this.test.fullTitle();
let testItem1 = await createDataObject('item', {libraryID: Zotero.Libraries.userLibraryID});