Don't change title when renaming from parent metadata (#4363)

This commit is contained in:
Abe Jellinek 2024-07-09 11:54:08 -04:00 committed by Dan Stillman
parent 327206f931
commit 9ea56705a0
2 changed files with 2 additions and 25 deletions

View file

@ -5672,7 +5672,6 @@ var ZoteroPane = new function()
if (ext) { if (ext) {
newName = newName + ext[0]; newName = newName + ext[0];
} }
let origFilenameNoExt = origFilename.replace(extRE, '')
var renamed = await item.renameAttachmentFile(newName, false, true); var renamed = await item.renameAttachmentFile(newName, false, true);
if (renamed !== true) { if (renamed !== true) {
@ -5680,13 +5679,6 @@ var ZoteroPane = new function()
continue; continue;
} }
// If the attachment title matched the filename, change it now
let origTitle = item.getField('title');
if (origTitle == origFilename || origTitle == origFilenameNoExt) {
item.setField('title', newName);
await item.saveTx();
}
let str = await document.l10n.formatValue('file-renaming-file-renamed-to', { filename: newName }); let str = await document.l10n.formatValue('file-renaming-file-renamed-to', { filename: newName });
progressWin.addLines(str, item.getItemTypeIconName()); progressWin.addLines(str, item.getItemTypeIconName());
progressWin.show(); progressWin.show();

View file

@ -671,7 +671,7 @@ describe("ZoteroPane", function() {
assert.equal(attachment.getField('title'), 'Image') assert.equal(attachment.getField('title'), 'Image')
}); });
it("should change attachment title if the same as filename", async function () { it("should not change attachment title even if the same as filename", async function () {
var item = createUnsavedDataObject('item'); var item = createUnsavedDataObject('item');
item.setField('title', 'Title'); item.setField('title', 'Title');
await item.saveTx(); await item.saveTx();
@ -683,22 +683,7 @@ describe("ZoteroPane", function() {
await zp.renameSelectedAttachmentsFromParents(); await zp.renameSelectedAttachmentsFromParents();
assert.equal(attachment.attachmentFilename, 'Title.png'); assert.equal(attachment.attachmentFilename, 'Title.png');
assert.equal(attachment.getField('title'), 'Title.png') assert.equal(attachment.getField('title'), 'test.png')
});
it("should change attachment title if the same as filename without extension", async function () {
var item = createUnsavedDataObject('item');
item.setField('title', 'Title');
await item.saveTx();
var attachment = await importFileAttachment('test.png', { parentItemID: item.id });
attachment.setField('title', 'test');
await attachment.saveTx();
await zp.selectItem(attachment.id);
await zp.renameSelectedAttachmentsFromParents();
assert.equal(attachment.attachmentFilename, 'Title.png');
assert.equal(attachment.getField('title'), 'Title.png')
}); });
}); });