Fix unintentional title transfer between attachments on item switch (#5245)

Also added similar test for item details table

Fixes #5244
This commit is contained in:
abaevbog 2025-05-02 22:34:06 -07:00 committed by Dan Stillman
parent 226ba8b489
commit bb79e10851
2 changed files with 40 additions and 0 deletions

View file

@ -221,6 +221,12 @@
if (!(val instanceof Zotero.Item)) {
throw new Error("'item' must be a Zotero.Item");
}
// Blur editable-text of old attachment. Otherwise, _handleTitleBlur() would fire after
// the new item is set but before updateInfo() sets the title field to have the new
// item's value, causing the old item's title to be set on the new item.
if (this._item && val.id != this._item.id && document.activeElement.closest("editable-text")) {
document.activeElement.blur();
}
if (val.isAttachment()) {
this._item = val;
this.hidden = false;

View file

@ -609,6 +609,25 @@ describe("Item pane", function () {
let fieldMode = newCreatorRow.querySelector("editable-text").getAttribute("fieldMode");
assert.equal(fieldMode, "0");
});
it("should save updated title when switching between items", async function () {
let itemOne = new Zotero.Item('book');
let itemTwo = new Zotero.Item('book');
itemOne.setField('title', 'Title_one');
await itemOne.saveTx();
await itemTwo.saveTx();
await ZoteroPane.selectItem(itemOne.id);
let itemDetails = ZoteroPane.itemPane._itemDetails;
let infoBox = itemDetails.getPane("info");
let titleField = infoBox.querySelector("#itembox-field-value-title");
titleField.focus();
titleField.value = "Updated title";
await ZoteroPane.selectItem(itemTwo.id);
await waitForNotifierEvent('modify', 'item');
assert.equal(itemOne.getDisplayTitle(), "Updated title");
});
});
describe("Libraries and collections pane", function () {
@ -1643,6 +1662,21 @@ describe("Item pane", function () {
attachmentBox._discardPreviewTimeout = currentDiscardTimeout;
});
it("should not transfer focused title while switching between items", async function () {
let item = new Zotero.Item('book');
let attachmentOne = await importFileAttachment('test.pdf', { title: 'PDF_one', parentItemID: item.id });
let attachmentTwo = await importFileAttachment('test.pdf', { title: 'PDF_two', parentItemID: item.id });
await ZoteroPane.selectItem(attachmentOne.id);
let itemDetails = ZoteroPane.itemPane._itemDetails;
let attachmentBox = itemDetails.getPane(paneID);
attachmentBox.querySelector("#title").focus();
await ZoteroPane.selectItem(attachmentTwo.id);
await waitForNotifierEvent('modify', 'item');
assert.equal(attachmentTwo.getDisplayTitle(), "PDF_two");
});
});