diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index e204b9e6b7..8f5bbe02c4 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -40,7 +40,6 @@ Cu.import("resource://gre/modules/osfile.jsm"); const CHILD_INDENT = 12; const COLORED_TAGS_RE = new RegExp("^[0-" + Zotero.Tags.MAX_COLORED_TAGS + "]{1}$"); const COLUMN_PREFS_FILEPATH = OS.Path.join(Zotero.Profile.dir, "treePrefs.json"); -const EMOJI_RE = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}|[\u200D\uFE0F]/gu; const HTML_NS = "http://www.w3.org/1999/xhtml"; const ATTACHMENT_STATE_LOAD_DELAY = 150; //ms @@ -3790,11 +3789,6 @@ var ItemTree = class ItemTree extends LibraryTree { || (item.isFileAttachment() && item.isTopLevelItem()); } - _isOnlyEmoji(str) { - // Remove emoji, Zero Width Joiner, and Variation Selector-16 and see if anything's left - return !str.replace(EMOJI_RE, ''); - } - _getTagSwatch(tag, color) { let span = document.createElementNS(HTML_NS, 'span'); span.className = 'tag-swatch'; @@ -3802,7 +3796,7 @@ var ItemTree = class ItemTree extends LibraryTree { // // TODO: Check for a maximum number of graphemes, which is hard to do // https://stackoverflow.com/a/54369605 - if (this._isOnlyEmoji(tag)) { + if (Zotero.Utilities.Internal.isOnlyEmoji(tag)) { span.textContent = tag; } // Otherwise display color diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index f4e077230a..590ca20029 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -405,6 +405,12 @@ Zotero.Utilities.Internal = { return s; }, + isOnlyEmoji: function (str) { + // Remove emoji and Variation Selector-16 and see if anything's left + const re = /\p{Extended_Pictographic}|\uFE0F/gu; + return !str.replace(re, ''); + }, + /** * Display a prompt from an error with custom buttons and a callback */ diff --git a/test/tests/utilities_internalTest.js b/test/tests/utilities_internalTest.js index 2e27ec6470..32dc432d48 100644 --- a/test/tests/utilities_internalTest.js +++ b/test/tests/utilities_internalTest.js @@ -68,6 +68,25 @@ describe("Zotero.Utilities.Internal", function () { }); + describe("#isOnlyEmoji()", function () { + it("should return true for emoji", function () { + assert.isTrue(Zotero.Utilities.Internal.isOnlyEmoji("🐩")); + }); + + it("should return true for emoji with text representation that use Variation Selector-16", function () { + assert.isTrue(Zotero.Utilities.Internal.isOnlyEmoji("⭐️")); + }); + + it("should return true for emoji made up of multiple characters with ZWJ", function () { + assert.isTrue(Zotero.Utilities.Internal.isOnlyEmoji("👨‍🌾")); + }); + + it("should return false for integer", function () { + assert.isFalse(Zotero.Utilities.Internal.isOnlyEmoji("0")); + }); + }); + + describe("#delayGenerator", function () { var spy;