Add support for displaying country flag emojis in the Items List (#5700)

This commit is contained in:
Tom Najdek 2026-01-13 17:50:47 +01:00 committed by GitHub
parent bed1d1ff35
commit d1d4065dae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 6 deletions

View file

@ -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

View file

@ -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;
},

View file

@ -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 () {