From 531e8697be28237ea7e3bb5d34b211245525ee8c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 14 Aug 2024 03:41:10 -0400 Subject: [PATCH] Fix additional breakage when bidi.browser.ui is true Broken by me in an edit to 181afb9 (#4534) Follow-up to previous commit --- .../content/zotero/xpcom/data/itemFields.js | 24 ++++++++++++++----- test/tests/itemFieldsTest.js | 10 ++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/itemFields.js b/chrome/content/zotero/xpcom/data/itemFields.js index 10834b570c..d18f6a08be 100644 --- a/chrome/content/zotero/xpcom/data/itemFields.js +++ b/chrome/content/zotero/xpcom/data/itemFields.js @@ -424,8 +424,24 @@ Zotero.ItemFields = new function() { * @returns {'auto' | 'ltr' | 'rtl'} */ this.getDirection = function (itemTypeID, field, itemLanguage) { - field = this.getName(this.getBaseIDFromTypeAndField(itemTypeID, field) || field); + // Primary fields: follow app locale switch (field) { + case 'dateAdded': + case 'dateModified': + case 'accessDate': + return Zotero.dir; + } + + var fieldName = this.getName(fieldName); + if (!fieldName) { + return 'auto'; + } + + var baseField = this.getBaseIDFromTypeAndField(itemTypeID, fieldName); + if (baseField) { + fieldName = this.getName(baseField); + } + switch (fieldName) { // Certain fields containing IDs, numbers, and data: always LTR case 'ISBN': case 'ISSN': @@ -449,11 +465,7 @@ Zotero.ItemFields = new function() { case 'language': case 'extra': return 'ltr'; - // Primary fields: follow app locale - case 'dateAdded': - case 'dateModified': - case 'accessDate': - return Zotero.dir; + // Everything else: guess based on the language if we have one; otherwise auto default: if (itemLanguage) { diff --git a/test/tests/itemFieldsTest.js b/test/tests/itemFieldsTest.js index 39e5a9b6ad..baf35ff764 100644 --- a/test/tests/itemFieldsTest.js +++ b/test/tests/itemFieldsTest.js @@ -44,4 +44,14 @@ describe("Zotero.ItemFields", function () { ); }); }); + + describe("#getDirection()", function () { + it("should return 'auto' for non-field", function () { + assert.equal(Zotero.ItemFields.getDirection('book', 'creator-0-lastName', ''), 'auto'); + }); + + it("should follow app locale for primary field", function () { + assert.equal(Zotero.ItemFields.getDirection('book', 'dateAdded', ''), Zotero.dir) + }); + }); })