Fix Emoji detection
And move to Zotero.Utilities.Internal.isOnlyEmoji() Fixes #2643
This commit is contained in:
parent
3481def4f6
commit
011b60af61
3 changed files with 26 additions and 7 deletions
|
@ -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 ATTACHMENT_STATE_LOAD_DELAY = 150; //ms
|
||||
|
||||
var ItemTree = class ItemTree extends LibraryTree {
|
||||
|
@ -3789,11 +3788,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.createElement('span');
|
||||
span.className = 'tag-swatch';
|
||||
|
@ -3801,7 +3795,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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue