From 4dbd52782c242d4f0f02c1130eee9236f32d977e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 19 Aug 2023 04:37:43 -0400 Subject: [PATCH] Better fixing of tab-title logic Follow-up to 3eef4284d17, which wasn't totally correct, and adds the attachment title before the parent metadata for secondary attachments. https://forums.zotero.org/discussion/comment/441362/#Comment_441362 --- chrome/content/zotero/xpcom/reader.js | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 4ccd7e87a1..a88c204f1b 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -545,34 +545,35 @@ class ReaderInstance { let readerTitle = item.getDisplayTitle(); let parentItem = item.parentItem; if (type === 'filename') { - let attachment = await parentItem.getBestAttachment(); - if (attachment && attachment.id === this._item.id) { - readerTitle = attachment.attachmentFilename; - } + readerTitle = item.attachmentFilename; } else if (parentItem) { - let attachment = await parentItem.getBestAttachment(); - if (attachment && attachment.id === this._item.id) { - let parts = []; - // Windows displays bidi control characters as placeholders in window titles, so strip them - // See https://github.com/mozilla-services/screenshots/issues/4863 - let unformatted = Zotero.isWin; - let creator = parentItem.getField('firstCreator', unformatted); - let year = parentItem.getField('year'); - let title = parentItem.getDisplayTitle(); - // If creator is missing fall back to titleCreatorYear - if (type === 'creatorYearTitle' && creator) { - parts = [creator, year, title]; - } - else if (type === 'title') { - parts = [title]; - } - // If type is titleCreatorYear, or is missing, or another type falls back - else { - parts = [title, creator, year]; - } - readerTitle = parts.filter(x => x).join(' - '); + let parts = []; + // Windows displays bidi control characters as placeholders in window titles, so strip them + // See https://github.com/mozilla-services/screenshots/issues/4863 + let unformatted = Zotero.isWin; + let creator = parentItem.getField('firstCreator', unformatted); + let year = parentItem.getField('year'); + let title = parentItem.getDisplayTitle(); + // If creator is missing fall back to titleCreatorYear + if (type === 'creatorYearTitle' && creator) { + parts = [creator, year, title]; } + else if (type === 'title') { + parts = [title]; + } + // If type is titleCreatorYear, or is missing, or another type falls back + else { + parts = [title, creator, year]; + } + + // If not primary attachment, add attachment title + let attachment = await parentItem.getBestAttachment(); + if (!attachment || attachment.id != item.id) { + parts.unshift(item.getDisplayTitle()); + } + + readerTitle = parts.filter(Boolean).join(' - '); } this._title = readerTitle; this._setTitleValue(readerTitle);