mirror of
https://github.com/zotero/zotero.git
synced 2026-09-11 22:51:15 +00:00
Add support for displaying country flag emojis in the Items List (#5700)
This commit is contained in:
parent
bed1d1ff35
commit
d1d4065dae
3 changed files with 13 additions and 6 deletions
|
|
@ -842,10 +842,9 @@ Zotero.Tags = new function () {
|
||||||
|
|
||||||
// Return the first sequence of emojis from a string
|
// Return the first sequence of emojis from a string
|
||||||
this.extractEmojiForItemsList = function (str) {
|
this.extractEmojiForItemsList = function (str) {
|
||||||
// Split by anything that is not an emoji, Zero Width Joiner, or Variation Selector-16
|
// Either match RGI_Emoji (which includes country flags) or any character followed by the Variation Selector-16
|
||||||
// And return first continuous span of emojis
|
let re = /(?:\p{RGI_Emoji}(?!\uFE0F)|.\uFE0F)+/gv;
|
||||||
let re = /[^\p{Extended_Pictographic}\u200D\uFE0F]+/gu;
|
return str.match(re)?.[0] || null;
|
||||||
return str.split(re).filter(Boolean)[0] || null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used as parameter for .sort() method on an array of tags
|
// Used as parameter for .sort() method on an array of tags
|
||||||
|
|
|
||||||
|
|
@ -388,13 +388,13 @@ Zotero.Utilities.Internal = {
|
||||||
},
|
},
|
||||||
|
|
||||||
containsEmoji: function (str) {
|
containsEmoji: function (str) {
|
||||||
let re = /\p{Extended_Pictographic}/gu;
|
let re = /\p{RGI_Emoji}/gv;
|
||||||
return !!str.match(re);
|
return !!str.match(re);
|
||||||
},
|
},
|
||||||
|
|
||||||
includesEmoji: function (str) {
|
includesEmoji: function (str) {
|
||||||
// Remove emoji, Zero Width Joiner, and Variation Selector-16 and compare lengths
|
// 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;
|
return str.replace(re, '').length !== str.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 () {
|
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 👨🏫."), "👨🌾👨🌾");
|
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 () {
|
describe("#compareTagsOrder()", function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue