From 2ee0feecc04c89e6ba56d2caaf62fed077106625 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 2 Dec 2025 15:29:55 -0500 Subject: [PATCH] EmojiSearch.addEmoji fixes CustomEmoji shortcodes - now `EmojiSearch.emoji` is truly immutable, in the sense that its members are not mutated after being inserted. - attempt to fix: https://todo.sr.ht/~singpolyma/soprani.ca/473 --- .../com/cheogram/android/EmojiSearch.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cheogram/java/com/cheogram/android/EmojiSearch.java b/src/cheogram/java/com/cheogram/android/EmojiSearch.java index d2d4d4ac3b19bdcf1c92de6d8814f04386d4dcc7..c94422688b1c4fe0a31bdec23c476bad198290fb 100644 --- a/src/cheogram/java/com/cheogram/android/EmojiSearch.java +++ b/src/cheogram/java/com/cheogram/android/EmojiSearch.java @@ -62,6 +62,15 @@ public class EmojiSearch { } public synchronized void addEmoji(final Emoji one) { + if (one instanceof CustomEmoji) { + for (Emoji e : emoji) { + if (one.shortcodeMatch(e.uniquePart())) { + one.shortcodes.clear(); + one.shortcodes.addAll(e.shortcodes); + break; + } + } + } emoji.add(one); } @@ -76,18 +85,6 @@ public class EmojiSearch { pq.addTopK(e, Math.max(shortcodeScore, tagScore), 10); } - for (BoundExtractedResult r : new ArrayList<>(pq)) { - for (Emoji e : emoji) { - if (e.shortcodeMatch(r.getReferent().uniquePart())) { - // hack see https://stackoverflow.com/questions/76880072/imagespan-with-emojicompat - e.shortcodes.clear(); - e.shortcodes.addAll(r.getReferent().shortcodes); - - pq.addTopK(e, r.getScore() - 1, 10); - } - } - } - List result = new ArrayList<>(); for (int i = 0; i < 10; i++) { BoundExtractedResult e = pq.poll();