From d1d4065dae77786cf3312d88f86502182a63c3ee Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Tue, 13 Jan 2026 17:50:47 +0100 Subject: [PATCH] Add support for displaying country flag emojis in the Items List (#5700) --- chrome/content/zotero/xpcom/data/tags.js | 7 +++---- chrome/content/zotero/xpcom/utilities_internal.js | 4 ++-- test/tests/tagsTest.js | 8 ++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 898cc231d5..dd0c09ffa4 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -842,10 +842,9 @@ Zotero.Tags = new function () { // Return the first sequence of emojis from a string this.extractEmojiForItemsList = function (str) { - // Split by anything that is not an emoji, Zero Width Joiner, or Variation Selector-16 - // And return first continuous span of emojis - let re = /[^\p{Extended_Pictographic}\u200D\uFE0F]+/gu; - return str.split(re).filter(Boolean)[0] || null; + // Either match RGI_Emoji (which includes country flags) or any character followed by the Variation Selector-16 + let re = /(?:\p{RGI_Emoji}(?!\uFE0F)|.\uFE0F)+/gv; + return str.match(re)?.[0] || null; }; // Used as parameter for .sort() method on an array of tags diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 57e0d54ee7..a0662d47e2 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -388,13 +388,13 @@ Zotero.Utilities.Internal = { }, containsEmoji: function (str) { - let re = /\p{Extended_Pictographic}/gu; + let re = /\p{RGI_Emoji}/gv; return !!str.match(re); }, includesEmoji: function (str) { // Remove emoji, Zero Width Joiner, and Variation Selector-16 and compare lengths - const re = /\p{Extended_Pictographic}|\u200D|\uFE0F/gu; + const re = /(?:\p{RGI_Emoji}(?!\uFE0F)|.\uFE0F)+/gv; return str.replace(re, '').length !== str.length; }, diff --git a/test/tests/tagsTest.js b/test/tests/tagsTest.js index f49de46ff9..301e1a291b 100644 --- a/test/tests/tagsTest.js +++ b/test/tests/tagsTest.js @@ -238,6 +238,14 @@ describe("Zotero.Tags", function () { it("should return first emoji span for text with an emoji made up of multiple characters with ZWJ", function () { assert.equal(Zotero.Tags.extractEmojiForItemsList("We are 👨‍🌾👨‍🌾. And I am a 👨‍🏫."), "👨‍🌾👨‍🌾"); }); + + it("should return first emoji span that contains RGI country flags", function () { + assert.equal(Zotero.Tags.extractEmojiForItemsList("Hello country flags 🇱🇺🇮🇪"), "🇱🇺🇮🇪"); + }); + + it("should return first emoji span that contains regional flags", function () { + assert.equal(Zotero.Tags.extractEmojiForItemsList("Hello England and Scotland: 🏴󠁧󠁢󠁥󠁮󠁧󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿"), "🏴󠁧󠁢󠁥󠁮󠁧󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿"); + }); }); describe("#compareTagsOrder()", function () {