4040import org .spongepowered .asm .mixin .injection .Redirect ;
4141import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
4242
43+ import java .util .Map ;
4344import java .util .concurrent .CompletableFuture ;
4445import java .util .regex .Matcher ;
4546import java .util .regex .Pattern ;
@@ -87,10 +88,22 @@ private void refreshEmojiSuggestion(CallbackInfo ci) {
8788 int start = neoLambda$getLastColon (textToCursor );
8889 if (start == -1 ) return ;
8990
90- String emojiString = typing .substring (start + 1 );
91+ Matcher emojiMatcher = EMOJI_PATTERN .matcher (textToCursor );
92+ Map <String , ?> emojiKeys = LambdaAtlas .INSTANCE .getKeys (RenderSettings .INSTANCE .getEmojiFont ());
93+ while (emojiMatcher .find ()) {
94+ int openingColon = emojiMatcher .start (1 );
95+ String key = emojiMatcher .group (2 );
96+ int closingColon = emojiMatcher .end (3 );
97+
98+ if (emojiKeys .containsKey (key ) && start >= openingColon && start < closingColon ) {
99+ // If the colon is part of a previous valid emoji, return
100+ return ;
101+ }
102+ }
103+
104+ String emojiString = textToCursor .substring (start + 1 );
91105
92- Stream <String > results = LambdaAtlas .INSTANCE .getKeys (RenderSettings .INSTANCE .getEmojiFont ())
93- .keySet ().stream ()
106+ Stream <String > results = emojiKeys .keySet ().stream ()
94107 .filter (s -> s .startsWith (emojiString ))
95108 .map (s -> s + ":" );
96109
@@ -105,6 +118,9 @@ private void refreshEmojiSuggestion(CallbackInfo ci) {
105118 @ Unique
106119 private static final Pattern COLON_PATTERN = Pattern .compile ("(:[a-zA-Z0-9_]+)" );
107120
121+ @ Unique
122+ private static final Pattern EMOJI_PATTERN = Pattern .compile ("(:)([a-zA-Z0-9_]+)(:)" );
123+
108124 @ Unique
109125 private int neoLambda$getLastColon (String input ) {
110126 if (Strings .isNullOrEmpty (input )) return -1 ;
0 commit comments